I noticed that arm-none-eabi-gcc 10.2 defines the macros UINTN_C in the following way (compiling with -mcpu=cortex-m7 -std=c99 -g3 -O0):
#define UINT32_C(x) __UINT32_C(x)
#define UINT16_C(x) __UINT16_C(x)
Then
#define __UINT32_C(c) c ## UL
#define __UINT16_C(c) c
The C99 standard (7.18.4.1 p2) says that:
The macro UINTN_C(value) shall expand to an unsigned integer constant with the specified value and type uint_leastN_t.
The 32 bits version is indeed expanding to an unsigned 32 bits representation (uint_least32_t is unsigned long on this CPU).
However the 16 bits version expands to a signed representation: UINT16_C(1) expands to 1 which is of type int.
Isn't it contradictory to the standard ? Is there an option of gcc that would fix that ?
Why not doing something like #define __UINT16_C(c) ((uint_least16_t)(c)) ?