size_t
is an unsigned type of at least 16 bits. Widths of 32 and 64 are often seen.
printf("%zu\n", some_size_t_object); // Standard since C99
Above is the best way going forward, yet if code needs to also port to pre-C99 platforms, covert the value to some wide type. unsigned long
is reasonable candidate yet may be lacking.
// OK, yet insufficient with large sizes > ULONG_MAX
printf("%lu\n", (unsigned long) some_size_t_object);
or with conditional code
#ifdef ULLONG_MAX
printf("%llu\n", (unsigned long long) some_size_t_object);
#else
printf("%lu\n", (unsigned long) some_size_t_object);
#endif
Lastly consider double
. It is a bit inefficient yet should handle all ancient and new platforms until about the years 2030-2040 considering Moore's law when double
may lack a precise result.
printf("%.0f\n", (double) some_size_t_object);