Use STR and CAT macros for # and ##

This commit is contained in:
Rangi42
2024-03-25 14:16:06 -04:00
parent 2b44672873
commit 8b6ae994b1
2 changed files with 7 additions and 3 deletions

View File

@@ -75,6 +75,10 @@ static inline int clz(unsigned int x) {
#define STR(x) #x
#define EXPAND_AND_STR(x) STR(x)
// Macros for concatenation
#define CAT(x, y) x##y
#define EXPAND_AND_CAT(x, y) CAT(x, y)
// Obtaining the size of an array; `arr` must be an expression, not a type!
// (Having two instances of `arr` is OK because the contents of `sizeof` are not evaluated.)
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof *(arr))

View File

@@ -1270,9 +1270,9 @@ int main(int argc, char *argv[]) {
#define SPEC_G TRASH_GLOBAL_SUM
#define overrideSpec(cur, bad) \
do { \
if (fixSpec & SPEC_##bad) \
fprintf(stderr, "warning: '" #cur "' overriding '" #bad "' in fix spec\n"); \
fixSpec = (fixSpec & ~SPEC_##bad) | SPEC_##cur; \
if (fixSpec & CAT(SPEC_, bad)) \
fprintf(stderr, "warning: '" STR(cur) "' overriding '" STR(bad) "' in fix spec\n"); \
fixSpec = (fixSpec & ~CAT(SPEC_, bad)) | CAT(SPEC_, cur); \
} while (0)
case 'l':
overrideSpec(l, L);