| Science Forum Index » Cryptography Forum » portably printing a size_t... |
|
Page 1 of 1 |
|
| 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 |
|
|
| Back to top |
|
|
|
| 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 |
|
|
| Back to top |
|
|
|
| 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. |
|
|
| Back to top |
|
|
|
| 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 |
|
|
| Back to top |
|
|
|
|