Tool to transpile C++ source code into C language

I have a C++ codebase that I’m currently building for different systems like Windows, Linux, ARM boards, and some gaming consoles. Now I need to port this code to a couple of embedded systems that only have C compilers available, no C++ support.

I remember reading that back in the day, some C++ compilers worked by translating C++ code into C code first, then using a regular C compiler to finish the job. Is there anything like this available today?

My current setup works with:

  • Visual Studio for Windows builds
  • GCC for Linux and ARM targets
  • Various embedded toolchains for specialized hardware

But I have two new target platforms (Renesas microcontrollers and Zilog Z8 family) where I only have C compilers. I’d really like to keep using my existing C++ codebase instead of rewriting everything in C.

Does anyone know of a modern tool that can convert C++ source files into equivalent C code? I’m hoping to find something that can handle basic C++ features like classes, constructors, and simple inheritance.

I worked on a similar project a few years back targeting older microcontrollers and found that Comeau C++ was one of the last commercial transpilers that actually converted C++ to C, but it’s no longer maintained. The reality is that most modern transpilation tools have been discontinued because the approach became impractical as C++ evolved. What I ended up doing was using LLVM’s intermediate representation as a bridge. You can compile your C++ code to LLVM IR, then use custom passes to generate C-like output, though this requires significant toolchain work. Another approach I’ve seen work reasonably well is using TinyCC or 8cc as references for generating simpler C constructs from parsed C++ AST. However, for embedded targets like Renesas and Zilog, you might want to consider creating a compatibility layer instead. Write your core logic in a C-compatible subset of C++ and use preprocessor macros to handle class-like structures and function pointers for method calls. This often produces more maintainable code than automated transpilation for resource-constrained environments.

honestly the transpiler route is gonna be rough for embedded stuff. i’d suggest just refactoring your c++ code to use c-style structs and function pointers instead - way more predictable than trying to automate the conversion. worked great when i had to port to pic microcontrollers last year.

wait, what specific c++ features are you actually using in your codebase? like are we talking heavy templating or just basic classes? might be easier to suggest alternatives if we know how complex your c++ code is. have you considerd checking if cfrontend or any old cfront derivatives still compile?