Convert from C++ into C plain
I have a very big C++ program. But now i have to convert it into C plain. Please tell me how I can do ? And about constructor and deconstructor, how can I rewrite them ?
Thanks for your attention.
Web Development
I have a very big C++ program. But now i have to convert it into C plain. Please tell me how I can do ? And about constructor and deconstructor, how can I rewrite them ?
Thanks for your attention.
by mightyduk
blood, sweat, and tears... Maybe this is a dumb question... why?
Can you use Object C? That may be an easier job.
Constructors/Destructors have no C equivalents, they are part of the object oriented features of C++, which you would have to rewrite extensively to make them work.
by tinnv
by dachev
No easy way.
C++ is a serious upgrade to the C language and many of it's abilities are not present in C. Constructors/Destructors are one of these upgrades.
You need to do everything by your self - manually calling constructors, manually take care about keeping the functions and data from one class together (eventually by arranging their names, or keeping them in different files), etc...
This will wriley be a lot of work. Sorry.
by tinnv
by wayne m.
If at all possible, I'd recommend finding a C++ compiler for your target machine. If that is not possible, here are some ideas off the top of my head:
Change all classes to structs
Rename all methods from Class::method to Class_Method. Constructors could become Class_Contstructor and Destructors could become Class_Destructor.
Separate overloaded methods with some extension.
Explicitly call the constructors and destructors when classes go out of scope.
Virtual functions will require a pointer to a jump table in the base class. Constructors will have to update this pointer as they are called. The base class virtual functions will have to call through this table.
Exception throws will have to be replaced with a call to the abort() function. There is no easy way to implement Exception Catch blocks.
A good reference showing how to convert between C and C++ is "Class Construction In C And C++" by Roger Sessions.
Good luck, this may be a difficult undertaking.
by tinnv
by jpereira
by tinnv
by tinnv
This discussion is closed to new replies.
Sort by Trending