A portable way to print an uintN_t object is to pass it to uintmax_t and use a length modifier j using the u conversion specifier:
printf("%ju\n", (uintmax_t)(UINT32_MAX));
j means that the argument is either intmax_t or uintmax_t ; u means it is unsigned, therefore it is uintmax_t .
Or you can use format strings defined in <inttypes.h> (in this case, you would use PRIu32 ):
printf("%" PRIu32 "\n", UINT32_MAX);
You cannot just use %u because it is not guaranteed that an int is represented by at least 32 bits (it only needs to be represented at least 16 bits).
James McNellis
source share