login
Header Space

 
 

Printing size_t or ssize_t variable

May 18, 2008 - 11:28am
Submitted by Eus on May 18, 2008 - 11:28am.

Looking at the man page of printf (man 3 printf), in the length modifier section, it is written:

z       A following integer conversion corresponds to a size_t or ssize_t argument. (Linux libc5 has Z with this meaning. Don't use it.)

Therefore,

size_t x = sizeof (int);

printf ("%zd\n", x);

But, it is said that the length modifier z exists only in C99 and newer systems.
Old systems don't recognize it. So, the old fashioned way to the the stuff is to perform explicit casting:

printf ("%lu\n", (unsigned long int) x);

Anyway, it's better to move to the new stuff.

Archive: All about C Programming

speck-geostationary