3 ms·
One minor point I've recently come across: GCC's old ## trick only works if preceded by a comma. This sometimes requires creating dummy macro arguments, if the
by o11c 3y ago
One minor point I've recently come across: GCC's old ## trick only works if preceded by a comma. This sometimes requires creating dummy macro arguments, if the optional argument pack needs to go at the front. The C23 way is more useful here.
Anyway, I got this working, for hygienic (shadow-proof) single-expansion macros:
#define MIN(a_, b_) \
({ \
/* auto a = (a_), b = (b_); ... except safe if the a_ or b_ expressions contain external a or b variables */ \
CLEANSE_MACRO_VARS((a, a_), (b, b_)); \
a < b ? a : b; \
})
Only the ({}) still requires a GNU extension; a `do-while` approach would require passing the output reference in as well, which is ugly.