Deciphering C++ compiler errors: Nonsensical errors from a function declaration
devblogs.microsoft.com
devblogs.microsoft.com
>
> > Indeed it does. Rats.
Not even the great Raymond Chen writes CVE free code.
I started using googletest in a project with a moderate amount of inline assembly, and of course I got some thoroughly confusing error messages after the substitution replaced the and and or opcodes.
Anyway, I didn't know that push_macro and pop_macro existed, so I'll have to revisit my previous hack around that issue.
In other words, maybe a computer flag would allow you to disable them being defined?
Although this could result in other issues...
In the GCC world, inline asm uses strings so macros don't cause problems.
#define foo(x) something
void foo(int a) {} // doesn't work
void (foo)(int a) {} // does work because 'foo)' can never be a function macroEvil evil evil. I get that sometimes they're unavoidable, but IMO you need to do everything you can to avoid them in C or C++. So many better options. Functions. Lambdas. Templated functions. ANYTHING but macros.
That said, I am not at all afraid of using macros when appropriate. Just give them names that scream "I_AM_A_MACRO" unless you take care to make them sufficiently function-like, and if public give them a "namespace" prefix either way.
#ifdef MY_MACRO
#error
#endif
edit: and #undef MY_MACRO after done using it, ideally.