我正在浏览一些gcc属性列表,我发现这个引起我注意的那个:
nothrow
The nothrow attribute is used to inform the compiler that a function cannot
throw an exception. For example, most functions in the standard C library can be
guaranteed not to throw an exception with the notable exceptions of qsort and
bsearch that take function pointer arguments. The nothrow attribute is not
implemented in GCC versions earlier than 3.3.
Run Code Online (Sandbox Code Playgroud)
C函数如何抛出异常?有人可以解释这个属性用于什么?
似乎有一个nothrow标签可用,但我发现那里似乎与C++有关std::nothrow.不确定这是否与我的特定问题有关.
这在从 C++ 代码调用 C 代码时具有重要意义,它向编译器保证 C 代码不会抛出异常以进行优化。如果它是 C 代码并且不能抛出异常,或者因为它是专门为从不抛出异常而编写的 C++,那么这非常有用。
因此,最终如果您正在编写纯 C 代码,您永远不需要这个,但是如果您认为有人可以从 C++ 中调用您的代码作为库,那么它会很方便。
| 归档时间: |
|
| 查看次数: |
1060 次 |
| 最近记录: |