General discussion

Locked

Convert from C++ into C plain

By tinnv ·
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.

This conversation is currently closed to new comments.

9 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Convert from C++ into C plain

by mightyduk In reply to Convert from C++ into C p ...

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.

Collapse -

Convert from C++ into C plain

by tinnv In reply to Convert from C++ into C p ...

The question was auto-closed by TechRepublic

Collapse -

Convert from C++ into C plain

by dachev In reply to Convert from C++ into C p ...

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.

Collapse -

Convert from C++ into C plain

by tinnv In reply to Convert from C++ into C p ...

The question was auto-closed by TechRepublic

Collapse -

Convert from C++ into C plain

by Wayne M. In reply to Convert from C++ into C p ...

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.

Collapse -

Convert from C++ into C plain

by tinnv In reply to Convert from C++ into C p ...

The question was auto-closed by TechRepublic

Collapse -

Convert from C++ into C plain

by jpereira In reply to Convert from C++ into C p ...

You don't say what your platform is. If it is Unix or Linux, then go to the GNU home page (www.gnu.org) and download the GNU compiler which has C++ support. If it's Windows, go to your local software store and buy Visual C++. You can justify the cost by pointing out that it is going to take days or weeks of your time to rewrite the code. Because, that's what it is - a rewrite.

Collapse -

Convert from C++ into C plain

by tinnv In reply to Convert from C++ into C p ...

The question was auto-closed by TechRepublic

Collapse -

Convert from C++ into C plain

by tinnv In reply to Convert from C++ into C p ...

This question was auto closed due to inactivity

Back to Web Development Forum
9 total posts (Page 1 of 1)  

Related Discussions

Related Forums