inconsistent printf() warning printing size_t
Mike Frysinger
vapier@gentoo.org
Sun Mar 15 22:03:00 GMT 2015
On 13 Mar 2015 14:20, Craig Howland wrote:
> On 03/13/2015 02:12 PM, Joel Sherrill wrote:
> > This code gives a warning on some targets and not on others.
> > Specifically, it gives a warning where size_t is long unsigned int
> > but not unsigned int. If you use %ld, it inverts when the warning
> > occurs. Any suggestions on how to portably print a size_t and
> > not get a warning?
> >
> > ==============
> > #include <stdio.h>
> >
> > void f( size_t x)
> > {
> > printf( "%d\n", x );
>
> printf("%zd\n", x);
> The 'z' length modifier means the conversion specifier applies to a size_t.
%zd is for ssize_t. you want %zu for size_t.
the reason for inconsistent warnings most likely is due to the sizeof(long) for
the target.
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://sourceware.org/pipermail/newlib/attachments/20150315/93715eaf/attachment.sig>
More information about the Newlib
mailing list