2 ms·
Some minor tweaks to what the author shows to make it even better. Give the macro a more descriptive name. For their example, call it GLOBAL_STRING instead of
by wat10000 2y ago
Some minor tweaks to what the author shows to make it even better.
Give the macro a more descriptive name. For their example, call it GLOBAL_STRING instead of X. I think this helps make things clearer.
#undef the macro at the end of the header. That removes one line of boilerplate from every use of the header.
Use #ifndef at the top of the header and emit a nice error if the macro isn't defined. This will make it easier to understand what's wrong if you forget the #define or misspell the macro.
- zem 2y agodespite the extra boilerplate, I feel like it's still better to undef the macros in the same scope they were defined in, so that they clearly delimit the code in which the macro is active.
- wat10000 2y agoI think this pattern is obvious enough that it's clear what's going on, but I can see where you're coming from.