On 5/17/24 4:51 PM, Bruno Haible wrote: > I think this produces wrong code with gcc 4.4.7 and older. See: > > -------------------------- foo.c -------------------------- > unsigned long long x = 0xff00000000000000; > ----------------------------------------------------------- > > $ gcc -Wall -S foo.c > foo.c:1: warning: integer constant is too large for ‘long’ type
I think I've seen warnings like this before with newer GCC versions but I am not sure if correct code was produced or not. I have always disliked the need for suffixes after integer constants in C (U, ULL, ULL, etc.). If stdint correctly defines UINT16_C, UINT32_C, and UINT64_C then I would just use those. POSIX states [1]: The macro INTN_C(value) shall expand to an integer constant expression corresponding to the type int_least N _t. The macro UINTN_C(value) shall expand to an integer constant expression corresponding to the type uint_least N _t. For example, if uint_least64_t is a name for the type unsigned long long, then UINT64_C(0x123) might expand to the integer constant 0x123ULL. I guess the regular U, UL, ULL suffix would work by themselves or a cast if preferred. Collin [1] https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/stdint.h.html