c++cperformancecompilationembedded

What is the cost of compiling a C program with a C++ compiler?


I want to use C with templates on a embedded environment and I wanted to know what is the cost of compiling a C program with a C++ compiler?

I'm interested in knowing if there will be more code than the one the C compiler will generate.

Note that as the program is a C program, is expect to call the C++ compiler without exception and RTTI support.


Solution

  • There's probably no 'cost', assuming that the two compilers are of equivalent quality. The traditional objection to this is that C++ is much more complex and so it's more likely that a C++ compiler will have bugs in it.

    Realistically, this is much less of a problem that it used to be, and I tend to do most of my embedded stuff now as a sort of horrible C/C++ hybrid - taking advantage of stronger typing and easier variable declaration rules, without incurring RTTI or exception handling overheads. If you're taking a given compiler (GCC, etc) and switching it from C to C++ mode, then much of what you have to worry about is common to the two languages anyway.