开发者

C code and C++ compiler

Does anyone know if there is any performance penalty if one compiles C code with C++ compiler? I have a C like code and use MinGW C++ compiler. I'm using qmake to compile the project. If there is a performance gain if I switch the compiler to co开发者_JS百科mpile in C, I'll have to update the code, there are some incompatibility with the syntax and want to know if it worth it.

Thanks.


There should be very little, if any, performance difference, to the point that if there is a difference, it will be very nearly immeasurably small - assuming you're using a C and C++ compiler from the same vendor or collection. Using a C compiler from one vendor and a C++ compiler from another will likely show larger differences, but only due to the fact that different vendors implement different optimization strategies.

There are a small number of potential optimization opportunities that C++ calls for that C compilers may not natively support - but again, unless they're from different vendors, the difference will be meaningless, and many compilers implement similar optimizations in both C++ and C compiler frontends.

One exception to this is Microsoft's compiler - Microsoft never made a C compiler, to my knowledge.

Note: I am assuming that the code does not use C++-specific features like templates or classes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜