简体   繁体   English

Visual Studio 2003编译器行为

[英]Visual Studio 2003 Compiler behaviour

I recently took over a project written in C and C++ that will be compiled using the MS Visual Studio 2003 compiler. 我最近接手了一个用C和C ++编写的项目,该项目将使用MS Visual Studio 2003编译器进行编译。 Since I have a little lack on experience with compiler settings and compiler output I want to know if the given setup realy makes a difference (according to compilation output or performance). 由于我对编译器设置和编译器输出缺乏经验,因此我想知道给定的设置是否确实有所作为(根据编译输出或性能)。

The project uses a mixture of C and C++. 该项目混合使用C和C ++。 The main part is written in C but uses some classes written in C++. 主要部分是用C编写的,但使用了一些用C ++编写的类。 So the first part of the question is: does the (MS VS 2003) compiler makes a difference per file (compiling plain c for .cpp files using only c functionality and compiling c++ style for files using the classes)? 所以问题的第一部分是:(MS VS 2003)编译器是否对每个文件有所不同(仅使用c功能为.​​cpp文件编译纯c并使用类为文件编译c ++样式)? Could there be a reason for using that (performance boost, backward compatibility)? 可能有使用它的理由(提高性能,向后兼容)吗?

The project also does not use try-catch blocks (since it is not plain C). 该项目也不使用try-catch块(因为它不是纯C语言)。 But the exception handling options in the compiler settings are not disabled. 但是不会禁用编译器设置中的异常处理选项。 So the second part of the question: could there be still a performance boost (or any other logical reason) for not using try-catch but NOT disabling it in the compiler? 所以问题的第二部分:不使用try-catch但不在编译器中禁用它,是否还会有性能提升(或任何其他逻辑原因)?

Yes, I am quite confused by this setup and trying to understand. 是的,我对这种设置和尝试理解感到困惑。

Fairly hard to decode, I'll give it a shot. 很难解码,我会试一试。 The default behavior is to get the C compiler when the source code filename extension ends in .c and the C++ compiler when it ends in .cpp. 默认行为是在源代码文件扩展名以.c结尾时获取C编译器,而在以.cpp结尾的C ++编译器中获取C编译器。 There is no greater scheme behind this, or anything having to do with backwards compatibility or perf improvements, a .cpp file is simply expected to contain C++ code. 这背后没有更大的方案,或者与向后兼容性或性能改进无关,仅.cpp文件可以包含C ++代码。 Both compilers use the same back-end (code generator and optimizer) so there will not be any great difference if you compile C code with the C++ compiler. 两种编译器都使用相同的后端(代码生成器和优化器),因此如果您使用C ++编译器编译C代码,则不会有太大区别。

The /EH compile option only does something if you create C++ objects in your code and the compiler can tell that an exception might be thrown. / EH编译选项仅在您在代码中创建C ++对象并且编译器可以告诉您可能抛出异常时才起作用。 If the codebase is largely C based then it won't make any difference. 如果代码库主要基于C,则不会有任何区别。 The actual cost of /EH is very low, a few cpu cycles to register an exception filter. / EH的实际成本非常低,只需几个cpu周期即可注册异常过滤器。 There's no cost when exception handling uses function tables but yours is almost surely too old to support that (/SAFESEH or x64 code). 当异常处理使用函数表时没有任何花费,但是您的表肯定已经太老了,无法支持它(/ SAFESEH或x64代码)。

If you just took over a large project then tinkering with the compiler settings ought to be a low priority. 如果您只是接手了一个大型项目,那么修改编译器设置应该是一个低优先级。 Get to know the codebase first before you start changing options that may break the code and will give you a hard time debugging the problem. 在开始更改可能会破坏代码的选项并让您很难调试问题之前,请先了解代码库。 Or to put it another way, avoid looking for the Deus Ex Machina that will make it look like you made a great achievement in very little time. 或者换一种说法,避免寻找Deus Ex Machina,它将使您看起来在很短的时间内就取得了巨大的成就。 Using a profiler will get you much more bang and a better insight. 使用探查器可以使您获得更多的收获,并获得更深入的了解。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM