I have a C++ project that works across many different systems like Windows, Linux, ARM boards, and some gaming consoles. Now I need to port this same code to two embedded systems that only have C compilers available, no C++ support.
I remember reading that some old C++ compilers worked by first converting C++ code to C code, then using a regular C compiler to finish the job. Does anyone know if there are modern tools that can do this kind of conversion?
My current setup looks like this:
Shared C++ Code Base
|
|-- Visual Studio --> Windows builds
|-- GCC x86 --> Linux builds
|-- GCC ARM --> Gaming console builds
|-- MBED compiler --> ARM development board
|-- Commercial compiler A --> Payment terminal platform A
|-- Commercial compiler B --> Payment terminal platform B
|-- Need solution --> Renesas microcontroller family
|-- Need solution --> Z8 microcontroller family
The last two targets have solid C compilers but zero C++ support. I really want to keep using the same shared library code across all platforms instead of maintaining separate C versions. Any suggestions for C++ to C translation tools that might work for this?
what c++ features are u using? templates and heavy stl stuff could make auto conversion really tricky. which specific constructs does ur shared code rely on? that might help decide if translation is realistic or if a wrapper is the way to go.
yeah, cfront is pretty outdated. a c wrapper sounds like a smart idea. it would let u keep using your c++ code while making it available for those c-only systems. just expose the necessary functions and you should be good to go!
You’re probably thinking of Cfront - early C++ compilers used it for exactly this. Modern alternatives are pretty limited since most development shifted to native C++ compilation. Comeau C++ still does C++ to C translation and supports tons of platforms, but it’s commercial. EDG’s frontend is another option some compiler vendors use for transpilation. Honestly though, I’d recommend a different approach based on what I’ve seen with similar cross-platform projects. Instead of translating your whole C++ codebase, restructure your shared library into a C-compatible core with C++ wrappers for platforms that support them. Use extern "C" interfaces and keep C+±specific features in separate abstraction layers. This ends up way more maintainable long-term, especially for embedded work where translated C++ code usually performs worse than C written from scratch.