From 8b6ae994b138af2654fedf5499a7a68269e507a5 Mon Sep 17 00:00:00 2001 From: Rangi42 Date: Mon, 25 Mar 2024 14:16:06 -0400 Subject: [PATCH] Use `STR` and `CAT` macros for `#` and `##` --- include/helpers.hpp | 4 ++++ src/fix/main.cpp | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/include/helpers.hpp b/include/helpers.hpp index 4183429a..3782c363 100644 --- a/include/helpers.hpp +++ b/include/helpers.hpp @@ -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)) diff --git a/src/fix/main.cpp b/src/fix/main.cpp index 90162d6d..f7a2055e 100644 --- a/src/fix/main.cpp +++ b/src/fix/main.cpp @@ -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);