Note: The differences between C and C++ syntax are already described on other posts... Still, something bothered me enough to prompt the following answer:
If I understood correctly, you want to have two separate parts in a program, one in C and one in C++. One supposed should have to be really fast, and the other could be slower.
In the current case (comparing C and C++ performance), there will be no visible difference if the same C code is compiled in with a C and in C++ compiler...
Of course, never underestimate how the skills of the programmer are important for the performance of a program, no matter the language.
Choosing a C compiler
Pros
- If you're lucky (using a recent gcc, or whatever), you'll be able to use C99 new features (note that C++ has most useful parts of C99 already available, either as native to the language, or in the standard library).
- You won't use a C++ feature by mistake, and thus, can safely bet you won't have surprises outside the K&R
Cons
- You won't be able to use C++ features
- Not every C compiler supports C99 (for example, Visual C++ is working hard to implement the newly C++0x standard, but did little work to implement C99)... So you could be stuck with C89 code if you work with, or target the wrong compiler.
Choosing a C++ compiler
Pros
- You'll have access to both C and C++ libraries
- You'll be able to use the STL and Boost
- You'll be able to write templated code (i.e. faster and safer than their
void *
counterparts).
- You'll be able to write all your code in C, excluding some minor details (C++ disallow implicit casting from
void *
, etc.). Fact is, the "minor details" above are considered as dangerous, which is why they generate errors or warnings on a C++ compiler.
Cons
- If you want to export functions with the C naming convention, you'll have to use the
extern "c"
specifier.
- You won't be able to implicitly cast from
void *
(note that this is not supposed to happen often, or even at all, in C++, so this a negligible problem when compared with potential casting errors)
- If you write C++ code, then you'll have to learn a lot more than simple C to get it right (RAII, constructors/destructors, exceptions, etc.)
Producing C/C++ code
By C/C++, I mean code that will be correctly understood by both C and C++ compilers. While your language of choice could vary, those compatible C/C++ header will be the same (even if you code in C++ and will provide additional C++ headers for C++ users of your code)
For your C code to be compatible with others' C++ code:
- decorate your function declarations with an
extern "C"
specifier, wrapped with #ifdef __cpluplus
. This will make sure a C++ compiler will know those functions are exported as C functions
- If you use them, don't let C99 features ever be seen by the C++ compiler. Some of those features will never ever be supported by any C++ compiler. Fact is, some major compilers won't even support C99 for their C compilers (see http://en.wikipedia.org/wiki/C99#Implementations)
- Avoid using C++ keywords, or at least, don't let the C++ compiler see them (i.e. exporting a function called
namespace
or class
or template
is a bad idea)
For your C++ code to be compatible with others' C code:
- provide alternative headers and functions wrapping C++ classes and functions. Don't punish the C++ folks by removing classes, etc., just because you want to remain compatible with C, but in the other hand, make sure the C folks will have reasonable access to your library without moving to a C++ compiler.
- In the headers writen for the C folks, decorate your function declarations with an
extern "C"
specifier, wrapped with #ifdef __cpluplus
. This will make sure a C++ compiler will know those functions are to be exported as C functions
Additional info
I found the following page quite interesting, as it lists the differences between C (including C99) and C++:
http://david.tribble.com/text/cdiffs.htm
Afterwords
Anyway, if C++ is considered fast and robust enough for the F-35, then it should be enough for you.
And apparently, they found it made their code writing faster, too (the code was mostly Ada, for the F-22, for example):
Unlike older generations of aircraft, such as the F-22, all software for the F-35 is written in C++ for faster code development.
Source: Wikipedia
So, if you need to choose, then choose your language because you like it, or because one as something the other has not. But not because of supposed performance difference.