如果同时指定 EHsc 和 EHa 会发生什么

发布于 2024-12-09 04:35:38 字数 383 浏览 0 评论 0原文

我正在处理遗留代码。

为了修复一些错误,我必须为某些文件提供 EHa。我测试了在构建时将 EHsc 和 EHa 赋予整个项目。这解决了我的问题,但发出警告说编译器正在用 EHa 覆盖 EH。 (选项顺序为:/EHsc /EHa) 仅当构建需要 EHa 的文件时才会出现此警告。它不会出现在只需要 EH 的源文件中。

<name of the file that needs EHa>\cl : warning D9025 : overriding '/EHs' with '/EHa'

我的问题是,这个警告是否说明了实际发生的情况? EHa 是否仅应用于实际需要 EHa 的源文件? (其他不需要EHa的文件是用EHsc构建的吗?)

谢谢。

I am handling a legacy code.

To fix some bug, I have to give EHa to some of the files. I tested giving both EHsc and EHa to the whole project when building. This solves my problem but gives warnings saying that compiler is overriding EHs with EHa.
(order of options is: /EHsc /EHa)
This warning occurs only when files that need EHa is being built. It doesn't appear on source files that only needs EHs.

<name of the file that needs EHa>\cl : warning D9025 : overriding '/EHs' with '/EHa'

My question is, does this warning tell what actually happens? Is EHa applied only on source files that actually need EHa? (Are the other files that do not need EHa built with EHsc?)

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

故人的歌 2024-12-16 04:35:38

/EHa 是“更强”的设置。它暗示 /EHsc,但确保即使抛出和捕获非 C++ 异常,也会调用 C++ 析构函数。 Windows 中的 SEH 异常。当代码生成器看不到括号内的代码抛出 C++ 异常的方法时,简单的 /EHsc 允许代码生成器优化代码并省略异常过滤器。这种优化不适用于 SEH 异常,例如任何语句都可能抛出 AccessViolation。

仅当您在程序中使用非标准 __try 和 __ except 关键字来捕获 SEH 异常时,才需要 /EHa。 AccessViolation、DivisionByZero、浮点异常、与使用 SEH 处理自身异常的语言运行时的互操作等。如果您使用它们,那么您必须确保您的所有代码都是使用/EHa 编译的。当捕获 SEH 异常时,错误可能会导致内存泄漏。

/EHa is the "stronger" setting. It implies /EHsc but ensures that C++ destructors are called even when a non C++ exception is thrown and caught. SEH exceptions in Windows. Just plain /EHsc allows the code generator to optimize the code and omit exception filters when it doesn't see a way for the bracketed code to throw a C++ exception. That kind of optimization cannot work for SEH exceptions, any statement can throw an AccessViolation for example.

You only need /EHa when you use the non-standard __try and __except keywords in your program to catch SEH exceptions. AccessViolation, DivisionByZero, floating point exceptions, interop with language runtimes that use SEH for their own exceptions, etcetera. If you use them then you have to make sure that all your code is compiled with /EHa. Getting that wrong can cause memory leaks when an SEH exception is caught.

心舞飞扬 2024-12-16 04:35:38

是的,警告告诉您发生了什么,因为发生的事情可能不是您想要的。这就是编译器警告背后的全部想法。

编译器不知道也不关心哪些文件“实际上需要 EHa”(在文件被编译之前,编译器无法告诉有关该文件的任何信息)。它会应用您告诉它应用的选项。当你告诉它两者都应用时,它会告诉你它会将其解释为你希望应用 EHA。

在调用编译器时指定每个矛盾的标志并不意味着“尝试编译器选项的所有可能组合,直到找到一个有效的组合”。

Yes, the warning tells you what happens, because what happens might not be what you intended. That's the entire idea behind compiler warnings.

The compiler doesn't know, or care, which files "actually need EHa" (until the file has been compiled, the compiler can't tell anything about the file). It applies the options you tell it to apply. And you tell it to apply both, and it tells you that it interprets this as if you want EHA to be applied.

Specifying every contradictory flag when invoking the compiler does not mean "try every possible combination of compiler options until you find one that works".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文