cross compiling

How to convert a C++ source code to a C source code. Is there any cross compiler for this already available.
or How to extract the properties of C++ (Inheritance, Polymorphism and Encapsulation) into the C Code.

How to go about doing the C++ source code to C source code
Who is Participating?
ramshakalConnect With a Mentor Commented:
You can translate C++ code to C code. You will have to find out whether your compiler support that or not. I am working on HP-UX. This has option to do that like
CC +i <nameofC++file>
It is supported on HP-C++ 12.10. So you just look in to different compile option and take help from help/programmer guide provided on unix system.

But it not a good idea. Because the genarated code will run into thousand line, and you may find it very difficult to understand and maintain.
gaatriAuthor Commented:
I need it very importantly.
so, can u make it fast.
Early C++ compilers used a pre-processor (cfront mostly) to convert C++ into C which would then be fed through a C compiler.

Of course these days nobody in their right mind would build a compiler in such a way.

Unless you can get hold of an old cfront based compiler (by the way it probably won't support templates or exceptions or a host of other stuff) I reckon you're stuffed.
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

There are modern compilers that do it this way (and no real reason why not).  The kai compiler ( is a very highly regarded optimizing C++ compiler that works this way.

But...if you expect the C code produced to be human editable/readable/maintainable, then I should forget the whole idea.
gaatriAuthor Commented:
Is there any other solution for converting C++ code to C,since presently I don't have HP-C++12.10,since my task is to completed immediately ,I would like to have an immediate solution to this.
Also if you can give me the guidelines
and suggestions on how to go about in converting the C++ code to C code keeping intact the characteristics of the oops concept,it would be helpful
PL reply immediately.
What you are asking is basically impossible without a lot of work.  i.e. to retain the OO characteristics in a C implementation, you would have to write a C framework which provided the required facilities.

BTW, none of the C++ compilers that generate C code will provide what you want,  they are -compiling- the code, and the back end is C.  Do not expect the generated code to be readable.

Why do you need this?  There are not many platforms that don't have a C++ compiler.
What do you need it for? Will you keep a C 'mirror' of an app coded in C++? Are you curious about the implementation?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.