Main Page | Report this Page
Science Forum Index  »  Cryptography Forum  »  portably printing a size_t...
Page 1 of 1    

portably printing a size_t...

Author Message
Francois Grieu...
Posted: Thu Oct 22, 2009 11:23 pm
Guest
How can we portably print (or convert to a string representation)
the value of a variable of type size_t?

Francois Grieu
 
Tom St Denis...
Posted: Fri Oct 23, 2009 1:58 am
Guest
On Oct 23, 1:23 am, Francois Grieu <fgr... at (no spam) gmail.com> wrote:
[quote]How can we portably print (or convert to a string representation)
the value of a variable of type size_t?

   Francois Grieu
[/quote]
man 3 printf

%z is your friend.

Tom
 
Noob...
Posted: Tue Oct 27, 2009 3:28 am
Guest
Francois Grieu wrote:

[quote]How can we portably print (or convert to a string representation)
the value of a variable of type size_t?
[/quote]
[Cross-posted to comp.lang.c]

C89 or C99 compiler?

What some people do is cast to unsigned long, and use %lu

This might fail on systems such as Win64, where a single object may be
larger than 2^32 bytes, yet unsigned long is only 32 bits wide.

Regards.
 
Richard Heathfield...
Posted: Tue Oct 27, 2009 3:45 am
Guest
In <hc6efm$pr7$1 at (no spam) aioe.org>, Noob wrote:

[quote]Francois Grieu wrote:

How can we portably print (or convert to a string representation)
the value of a variable of type size_t?

[Cross-posted to comp.lang.c]

C89 or C99 compiler?

What some people do is cast to unsigned long, and use %lu

This might fail on systems such as Win64, where a single object may
be larger than 2^32 bytes, yet unsigned long is only 32 bits wide.
[/quote]
And even under those circumstances, it will only fail for objects at
least that large. Furthermore, IIRC the worst that can happen is that
you'll get the wrong value. That's bad enough, of course, but at
least you won't get a crash - the result will be determinate, and
thus amenable to testing.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh at (no spam)
"Usenet is a strange place" - dmr 29 July 1999
Sig line vacant - apply within
 
 
Page 1 of 1    
All times are GMT - 5 Hours
The time now is Fri Nov 27, 2009 10:45 pm