I was taking a look through some of the gcc attributes list and I spotted this one that caught my attention:
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.
How could a C function throw an exception? Could someone explain what this attribute is used for?
There seems to be a nothrow
tag available but what I've found there seem to be related to C++ std::nothrow
. Not sure whether that's related to my particular question.
This has significance when calling C code from C++ code, it guarantees to the compiler for optimization purposes that the C code cannot throw exceptions. This is useful if either it is C code and cannot throw, or because it is C++ written specifically to never throw up an exception.
So ultimately if you are writing pure C you should never need this, however if you think someone may call your code from C++ as a library it can be handy.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With