I have a program which is configured by the user by using C++ classes and the same class should be used to configure a program which can only use a subset of C99 (Open CL Language).
So my question is: Is there a way to compile C++ to C-Code?
Open Source would be great!
The Comeau compiler seems to be able to do that. From Wikipedia "Rather than produce an executable directly, Comeau C/C++ outputs C code and requires a separate C compiler in order to produce the final program."
I have never tried it, though.
The C++ FAQ has a list of possibilities: Is it possible to convert C++ to C?.
In short, it says that you can't expect this to give you particularly readable code. Think of the complexities involved; multiple inheritance, virtual-function resolution, templates, operator overloading, etc., etc. There's no
cleansuccinct way of expressing these concepts in pure C. If all you're after is compilable C, though, then this is probably the way to go.You could use the clang C++ frontend to generate llvm bytecode, and use
llc
to emit C code, see llc doc, especially thec
option. Both are open source, with BSD like licenses.http://www.cs.technion.ac.il/users/yechiel/c++-faq/convert-to-c.html