This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: inconsistent printf() warning printing size_t


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

Attachment: signature.asc
Description: Digital signature


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]