What printf format should I use for a typedef like size_t when I don't know whether it is long or some other type?

Q

What printf format should I use for a typedef like size_t when I don't know whether it is long or some other type?

✍: Guest

A

Use a cast to convert the value to a known, conservatively-sized type, then use the printf format matching that type. For example, to print the size of a type, you might use
printf("%lu", (unsigned long)sizeof(thetype));

2015-11-04, 1242👍, 0💬