gcc – 属性nothrow用于什么?

我正在浏览一些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函数如何抛出exception? 有人可以解释这个属性用于什么?

似乎有一个nothrow标签可用,但我发现那里似乎与C ++ std::nothrow 。 不确定这是否与我的特定问题有关。

这在从C ++代码调用C代码时具有重要意义,它保证了编译器的优化目的,即C代码不能抛出exception。 如果它是C代码并且不能抛出,或者因为它是专门编写的C ++从不抛出exception,这很有用。

所以最终如果你正在编写纯C,你应该永远不需要这个,但是如果你认为有人可能会将你的代码从C ++称为库,那么它可以很方便。