From e1ebfe7f258c1c99006fee8a3b6e111dc1d34d79 Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Sun, 22 Jan 2023 23:34:16 -0500 Subject: [PATCH] xtra: Avoid undefined ## usage. According to the C spec, every use of the ## operator has to produce a valid preprocessing token, otherwise the behaviour is undefined. It is not enough to merely ensure that a sequence of ## operators results in a valid token at the end. This matters in practice, as at least some versions of the Sun Studio compiler will turn: #define PASTE(a, b) a ## b #define PASTE2(a, b) PASTE(a, b) PASTE2(uint_least, PASTE(8, _t)) into two tokens: uint_least8 _t instead of uint_least8_t as desired. The results are not good for the XTRA_PACKED_LOPTS macro. Fortunately, it is straightforward to rearrange the expansions to avoid this problem. --- src/xtra.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/xtra.h b/src/xtra.h index 4de8df5..1296321 100644 --- a/src/xtra.h +++ b/src/xtra.h @@ -30,7 +30,7 @@ * The uint_leastXX_t typedefs must be in scope in order to use this macro. */ #define XTRA_PACKED_LOPTS(name) \ - static const XTRA_PASTE2(uint_least, XTRA_PASTE2(LOPT_PACK_BITS2, _t)) \ + static const XTRA_PASTE2(XTRA_PASTE2(uint_least, LOPT_PACK_BITS2), _t) \ name##_packed[] = { LOPTS_PACKED_INITIALIZER }; \ struct option name[XTRA_ARRAYSIZE(name##_packed) + 1] = {0}; \ do { \ -- 2.43.2