我查看了一些 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.
C 函数怎么会抛出异常呢?有人能解释一下这个属性的用途吗?
似乎有一个nothrow
标签可用,但我发现那里似乎与 C++ 有关std::nothrow
。不确定这是否与我的特定问题有关。
这在从 C++ 代码调用 C 代码时具有重要意义,它向编译器保证 C 代码不会抛出异常以进行优化。如果它是 C 代码并且不能抛出异常,或者因为它是专门为从不抛出异常而编写的 C++,那么这非常有用。
因此,最终如果您正在编写纯 C 代码,您永远不需要这个,但是如果您认为有人可以从 C++ 中调用您的代码作为库,那么它会很方便。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)