This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC 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: Incorrect warning about printf %0<fieldwidth>p format


Please explain.  The man text you quote says that the 0 flag has
undefined behavior for "other" conversions if a precision is specified.
But precision is not specified in this case; only a minimum field width.
Therefore that clause is not relevant.

The man page does not explicitly say what happens if the 0 flag is
used with %p, but that is almost certainly a typo (p should have been
included in the list of conversions which support leading zeroes).  

In any case, the code is the truth: 

%0<fieldwidth>p works and is the *only* portable way to print pointer
values with leading zeroes (the alternatives require platform-dependent
casts to an integer type).

IN SUMMARY: There is no other way to code it, so gcc should not
complain.

On Wed, 2003-05-07 at 11:23, Falk Hueffner wrote:
> Jim Avera <jima@cadence.com> writes:
> 
> > gcc 3.2 (-Wall) incorrectly complains about the following:
> > 
> >      void *ptr;
> >      printf("The pointer is %010p\n", ptr);
> > 
> >      ...: warning: `0' flag used with `%p' printf format
> > 
> > The '0' flag is perfectly legitimate
> 
> No, it's not.
> 
> §7.19.6.1:
> 
> 0  For d, i, o, u, x, X, a, A, e, E, f, F, g, and G conversions,
>    leading zeros (following any indication of sign or base) are used to
>    pad to the field width rather than performing space padding, except
>    when converting an infinity or NaN. If the 0 and - flags both
>    appear, the 0 flag is ignored. For d, i, o, u, x, and X conversions,
>    if a precision is specified, the 0 flag is ignored. For other
>    conversions, the behavior is undefined.


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