Note. The differences between the syntax of C and C ++ are already described in other posts ... However, something bothered me enough to trigger the following answer:
If I understand correctly, you want to have two separate parts in the program: one in C and one in C ++. Each was supposed to be very fast and the other to be slower.
In the current case (comparing the performance of C and C ++) there will be no noticeable difference if the same C code is compiled with C and in the C ++ compiler ...
Of course, never underestimate how important programmer skills are for running a program, regardless of language.
Choosing a C Compiler
Pros
- If you're lucky (using recent gcc or something else), you can use the new C99 features (note that C ++ has most of the useful parts of C99 that are already available, either as native language or standard library).
- By mistake, you will not use the C ++ function, and thus, you can safely say that you will not have surprises outside of K & R
Against
- You cannot use C ++ functions.
- Not every C compiler supports C99 (for example, Visual C ++ is working to implement the new C ++ 0x standard, but has done a bit of work to implement C99) ... So you can get stuck with C89 if you work or aim for the wrong compiler.
Choosing a C ++ Compiler
Pros
- You will have access to the C and C ++ libraries.
- You can use STL and Boost
- You can write boilerplate code (i.e. faster and safer than
void * copies of it). - You can write all your code in C, with the exception of some minor details (C ++ prohibits implicit casting from
void * , etc.). The fact is that the βminor details" above are considered dangerous, so they generate errors or warnings in the C ++ compiler.
Against
- If you want to export functions using the C naming convention, you have to use the
extern "c" qualifier. - You cannot indirectly drop from
void * (note that this should not happen often or even in general in C ++, so this is a minor problem compared to potential casting errors) - If you write code in C ++, you will need to learn much more than just C in order to get it correctly ( RAII , constructors / destructors, exceptions, etc.)
C / C ++ Code Generation
In C / C ++, I mean code that will be correctly understood by both C compilers and C ++. Although your choice language may differ, these compatible C / C ++ headers will be the same (even if you are C ++ code and provide additional C ++ headers for C ++ users of your code)
If your C code is compatible with other users' C ++ code:
- decorate function declarations with the
extern "c" specifier wrapped in #ifdef __cpluplus . This will ensure that the C ++ compiler knows that these functions are exported as C. functions. - If you use them, do not let C99 functions ever see the C ++ compiler. Some of these functions will never be supported by any C ++ compiler. The fact is that some large compilers do not 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 (e.g. exporting a function named
namespace or class or template is a bad idea)
In order for your C ++ code to be compatible with the C code of other users:
- provide alternative headers and functions that wrap C ++ classes and functions. Do not punish C ++ people by deleting classes, etc., Just because you want to remain compatible with C, but, on the other hand, make sure that C people will have reasonable access to your library without going to the C compiler ++.
- In the headings written for C people, decorate function declarations with the
extern "c" specifier wrapped in #ifdef __cpluplus . This will make sure that the C ++ compiler knows that these functions should be exported as C. functions.
Additional Information
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
As for the C99 functions that are missing in C ++, you can read my answer to the question What can be done in c, but not C ++? : I describe the features of C ++ that easily replace those C99 functions.
Afterword
In any case, if C ++ is considered fast and reliable for the F-35 , that should be enough for you.
Most F-35 software is written in C and C ++ because of the availability of the program; Ada83 code is also reused with F-22.
Source: Wikipedia: https://en.wikipedia.org/wiki/Lockheed_Martin_F-35_Lightning_II
So, if you need to choose, then choose your language because you like it, or because it somehow has no other. But not because of the supposed difference in performance.
paercebal
source share