I am currently working on a mixed C and C++ project. Lately it happened that external library I have no control over added an inline function containing register keyword to header. For simplicity let's assume header looks like this:
// external_header.h
inline int do_stuff() {
register int res = 1;
return res;
}
// some functions declarations without name mangling
And let's assume this is my code (as usless as it is):
// my_code.cpp
#ifdef __cplusplus
extern "C"{
#endif
#include <external_header.h>
#ifdef __cplusplus
}
#endif
int main(inc argc, char** argv) {
return 0;
}
Compiling my_code.cpp with C++17 switch gives error like this:
error: ISO C++17 does not allow ‘register’ storage class specifier [-Werror=register]
Can there be anything done to work around this error? If so, what is to be done?
Using compiler options, you can disable the -Werror flag for this warning only:
-Werror -Wno-error=register
Or you can disable this warning altogether:
-Wno-register
Or within the code you could use preprocessor macro to remove this keyword. Note that replacing keywords (even unused ones like register) is Undefined Behaviour.
#ifdef __cplusplus
extern "C"{
#endif
#define register
#include <external_header.h>
#undef register
#ifdef __cplusplus
}
#endif
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