![]() |
|
#1
|
|||
|
|||
|
Need a guideline in porting cpp to c
How are you doing?
I'm trying to port cpp code to c. It's not a huge code. But I'm kind of an old style guy so I feel dizzy. I'm studying cpp syntax again cause I forgot it almost. Anyway, is there any guidance fot this subject? If so please let me know. I googled the net but with no succeed. By the way I found Comeau C/C++ compiler can convert cpp source to c. Does anybody have tried it before? Is it reliable? Thanks for reading. |
|
#2
|
|||
|
|||
|
As far as I know most of C++ compilers first convert C++ code to C before compiling.
I've used convertors, none of them is 100% reliable. You can use another way to do your job by static linking . First compile your C++ codes using C++ compilers and make .LIB file. Then you can use extern in your C codes to use methods from your compiled C++ code (.lib) Your C compiler will link the lib file to your final exe and the job is done. Regards OMID |
|
#3
|
|||
|
|||
|
Hi,
it's not quite clear, what you want to do : - port the C++ source code to C ... - use your C++ code from some other C stuff ... Kerstin |
|
#4
|
|||
|
|||
|
Thanks for your answers.
My aim is porting cpp code to asm. Porting to c is an intermediate step. I want to optimize the code and make it smaller, run faster and so on. It would be better if I can convert it directly to asm. But It looks little bit hard (for me) because of many injected codes by cpp compiler. I think I need to understand the code first. That's why I'm porting it to c. But many features of cpp are hard to port to c. I just wonder if there are any tips or guidances for doing that. |
|
#5
|
|||
|
|||
|
If you want to port C++ into ASM you should use the Borland C++ compiler. It has an option called "compile via assembly" (commandline switch "-B"). This first translates the CPP file to ASM and then passes it to TASM32.
If you rename TASM32.EXE to something else you will get an error message, but BCC32 won't delete the ASM file so you can take the code you want out of it. |
|
#6
|
|||
|
|||
|
The original C++ compiler by Bjarne Stroustroup (called cfront) converts c++ to c. You might be able to find it by searching for cfront on the net.
|
|
#7
|
|||
|
|||
|
Quote:
|
|
#8
|
|||
|
|||
|
Wow it works.
Although it looks messy, anyway I got an asm form of it. I'm ashamed of my ignorance. Thank you again. You guys really helped me. |
|
#9
|
|||
|
|||
|
there is a good book on this
There is a book
Stanley B. Lippman : Inside the C++ Object Model that goes through the C++ language elements one by one and shows how they are actually compiled to C (based on the cfront compiler). It covers all the issues including virtual base classes and all kinds of member function pointers as well. Quote:
AFAIK I have this book in digital format. PM me if you want it to be uploaded or e-mailed to you. Last edited by mihaliczaj; 01-18-2005 at 20:26. |
|
#10
|
|||
|
|||
|
You mean "Inside the C++ Object Model"?
Title is little different but same author. I could find it on the net. Thank you for your concern. |
|
#11
|
|||
|
|||
|
Quote:
To get a real benefit, you should try to catch the algorithm(s) used and reimplement them from scratch ... Kerstin |
|
#12
|
|||
|
|||
|
nuemga2000 // That's what I'm talking about. I agree with you.
I'm still trying to understand that code. Compiler produced asm code is just a reference. Better than nothing. |
|
#13
|
|||
|
|||
|
Quote:
Are you sure that the asm code is the best way to understand the code? You loose all the info that is buried in the source code (variable/function names etc.). Isn't it easier simply debug the application step by step? Even if you are not a C++ expert this would be much easier IMHO. In most debuggers there is a mixed C++/asm view where you can debug the asm if you want, and you can see to what asm code the C++ source is compiled. |
|
#14
|
|||
|
|||
|
Well, I'll rewrite it with asm from the scratch. So It should be free from variable/function name problem.
And of course I'm using debugger almost everytime along with cpp source and compiler produced asm source. Compiler produced asm source has name information so it's worth to take a look. |
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Ollydbg v1 to v2 porting question | sendersu | General Discussion | 0 | 09-02-2014 13:29 |
| porting GNU tdestroy() function to SPARC Solaris | WhoCares | General Discussion | 3 | 01-07-2005 23:53 |