Is there a way (compiler extensions are acceptable) to include C headers and mark included C functions as noexcept
, but without modifying headers?
For example, I have a C library and its header header.h
. No C++ callback will be passed into it so it never throws. Can I mark the included C functions as noexcept
or tell compiler that they never throw, so that the compiler doesn't have to generate unused code and enable some possible optimizations for callers? Note that the C++ code using the C library should still be able to use exceptions (so disabling exceptions for the entire program is not an option).
extern "C" {
#include "header.h" // Is there a way to mark included C functions here as noexcept?
}