In one C ++ example, the restrict keyword is missing. Used correctly, which sometimes allows the compiler to create faster code.
- in practice, it’s quite rare to see the benefits of
restrict , but this happens, - There are many cases where the C ++ or C compiler can infer (after embedding) that the necessary conditions for
restrict apply, and act accordingly even if the keyword is not used, - C ++ compilers, which are also C compilers, can provide
restrict or __restrict as an extension anyway.
But sometimes (or quite often in some domains) restrict is a really good optimization, which I am talking about is one of the reasons for using Fortran. This, of course, is one of the reasons for strict alias rules in both C and C ++, which offer the same optimization opportunity as restrict for a more limited set of conditions.
If you “think,” it depends on what you think is the “equivalent code.” restrict never changes the value of the program that uses it - compilers can ignore it. Therefore, it is not necessary to describe a program that uses it (for the eyes of the C compiler) and a program that does not execute (for C ++) as "equivalent." The restrict version took more (perhaps only a little more) the programmer’s efforts to create, since the programmer must be sure that he will fix it before using it.
If you mean if there is a program that is valid C and also valid C ++ and has the same meaning for both, but the implementations are somehow limited by the C ++ standard to run it slower than the C implementations, then I'm pretty sure the answer is no. If you mean if there are any potential performance improvements available in the C standard, but not in the standard C ++, then the answer is yes.
If you can get any benefit from customization, it’s another matter: will you get more benefit for the same amount of effort with a different optimization available in both languages, it’s different, and will there be any benefit big enough to base your choice of language on -still remains different. It is ridiculously easy to interact between C and C ++ code, so if you have any reason to prefer C ++, then, like any optimization that changes your preferred coding method, switching to C will usually be something what you do when your profiler says you are too slow, not before.
Also, I'm trying to convince myself, one way or another, whether the performance for exceptions depends, assuming you never use any type that has a non-trivial destructor. I suspect that in practice this is possible (and that this contradicts the principle of "do not pay for what you do not use"), if only because otherwise there would be no gcc point with -fno-exceptions . C ++ implementations reduce the cost quite low (and this is mainly in rhodates, not in the code), but this does not mean that it is equal to zero. Time-critical critical code may or may not be critical for binary code.
Again, this may depend on what you mean by "equivalent" code - if I need to compile my so-called "standard C ++ program" using a non-standard compiler (for example, g++ -fno-exceptions ) to "prove", Since C ++ code is as good as C, in a sense, the C ++ standard is worth something to me.
Finally, the C ++ runtime environment itself has an initial cost that is not necessarily identical to the initial cost of starting C for the "same" program. You can hack altogether in order to lower the cost by removing things that you don’t need strictly. But this effort, the implementation does not necessarily do this for you completely every time, therefore it is not entirely true that in C ++ you are not paying for what you are not using. That is a general principle, but its achievement is a problem of implementation quality.