The directive of the #define preprocessor can define and override the macro. But its syntax is such that it is not clear what exactly it does (defines or overrides). In order to understand what it does, you need to take into account which preprocessor directives were executed earlier. It follows from this that a programmer who wants to define a macro may mistakenly override a macro that has been defined somewhere deep in the connected header file. This will lead to an error that is difficult to find. What code can strictly:
- define macro
- override macro
I wrote this code:
#define safe_define(def, val) \ #ifdef def \ #error "DEFINED!" \ #else \ #define def val \ #endif // def The compiler generates an error on the first line of this code:
main.cpp | 17 | error: '#' is not followed by a macro parameter