views:

560

answers:

6

I'm currently managing some C++ code that runs on multiple platforms from a single source tree (Win32, Linux, Verifone CC terminals, MBED and even the Nintendo GBA/DS). However I need to build an app targetted at an embedded platform for which there is no C++ compiler (C only). I remmber that many of the early C++ compilers were only front-ends stitting on existing C compilers (Glockenspiel for example used MSC). Are there any such 'frontend' C++ compilers in use today that will generate C code.

                      Tools            Platform
                      -----------      ------------

                ______Visual C++ _____ WIN32
               /
              /_______MBED (ARM)_______MBED (ARM dev board).
             /
            /_________GCC (x86)________Linux
           /
Source____/___________GCC (ARM)________GBA/DS
          \
           \__________SDA______________Verifone Verix CC Terminals
            \
             \________ARM SDT__________Verifine VerixV CC terminals
              \
               \______????_____________Renases M8/16/32.
                \
                 \____????_____________Z8 family.

The last two platforms I have good C compilers for but no C++.

As you can see I'm supporting a large variety of platforms and I share a large body of library code (and some app code).

+15  A: 

Comeau C++ does this.

Michael Burr
Was going to say the same but you beat me to it by 11 seconds
Phil Nash
I think I've come across this compiler before. The only iussue is that the problem platform are for hobby use only. As far as I can recollect the Comeau compiler is a tad expensive.I'm using the ARM SDT for work (expensive but the job pays).I also use Visual Studio 2008 at work (again paid for by work).I used Visual Studio Express at home.
Tim Ring
Wow, it's "breathtaking," "amazing," "fabulous," and they even have a blinking javascript link that floats on top of the text urging you to purchase it!
Seth Johnson
@Seth: the web site is a bit overboard, but it *is* the best C++ compiler around, at least in terms of conformance.
Jerry Coffin
@JudgeDread: at least the normal Windows version of Comeau C++ is decidedly inexpensive -- $50US/copy. I'm not sure what they charge to port it to other targets though.
Jerry Coffin
Michael Burr
@Seth - the site is quite a sight. And if you decide to buy, the order page is pretty fun too.
Michael Burr
+1  A: 

Out of date, but maybe you want to try cfront?

I'll leave this for information - cfront doesn't have exception support.

plinth
To old, a bit like myself :)
Tim Ring
+2  A: 

Comeau C++ generates C as its output, and they seem to be quite happy to port it to work with different back-end compilers, though I'm not sure about the exact pricing for that.

If you want a bit more of a "roll your own" approach, you could buy a license to the EDG C++ compiler. It's normally used as a front-end (e.g. by Comeau and Intel) but I believe as it's shipped, it includes a code generator that produces C as its output. Its licensing is oriented more toward compiler vendors, though, so a license gives you a lot of rights, but is pretty expensive.

Jerry Coffin
+16  A: 

If you use LLVM, llvm-g++ will compile your C++ code to LLVM bitcode, and llc has a backend which converts bitcode to C.

You could write commands like this:

llvm-g++ -emit-llvm -c foo.cpp -o foo.o
llc -march=c <foo.o >foo.c
Jay Conrod
I like the look of this, will explore further, thanks....
Tim Ring
+5  A: 

Can't help with the Z8, but the Renesas M16C/M32C family has GCC these days - see http://www.kpitgnutools.com/ for prebuilt cross toolchain hosted on Windows. Haven't used it myself yet but may be a better option than a 3rd party C++ frontend, especially as your code already targets GCC on other platforms.

quietbob
Thanks, will check it out (I'm currrently using the Glyn dev boards for R8 m using has a similar form factor.
Tim Ring
+1  A: 

Of what I have understood, the c++ support in gcc for r8c/m16c/r32c isn't quite mature and good enough for production code. But for r8c/m16c/m32c/r32c there is at least one compiler supporting embedded C++ and that is IAR, I think Tasking also supports embedded C++ on m16c.

henkebenke
Thanks for info, will follow up on IAR compiler (used it before on H8)...
Tim Ring