Mail Archives: djgpp-workers/2002/09/05/17:19:27
Richard said:
> > 08/03/2002 16:31:03: Create 000354:2.03 printf()'s %#08x handling of 0 wrong <ams AT ludd DOT luth DOT se>
> > ----- c.c starts. -----
> > #include <stdio.h>
> >
> > int main(void)
> > {
> >
> > printf("%#08x %#08x\n", 1, 0);
> >
> > return 0;
> > }
> > ----- c.c ends. -----
> [snip]
> > > ./c
> > 0x000001 00000000
> >
> > Expected result:
> > 0x000001 0x000000
> >
> > Note how the "x" is a zero.
>
> I think you are expecting the wrong thing. Here's what SUSv2 says about the
> '#' flag in its page about fprintf:
>
> "#
> This flag specifies that the value is to be converted to an alternative form.
> For o conversion, it increases the precision (if necessary) to force the first
> digit of the result to be 0. For x or X conversions, a non-zero result will
> have 0x (or 0X) prefixed to it. For e, E, f, g or G conversions, the result
> will always contain a radix character, even if no digits follow the radix
> character. Without this flag, a radix character appears in the result of these
> conversions only if a digit follows it. For g and G conversions, trailing
> zeros will not be removed from the result as they normally are. For other
> conversions, the behaviour is undefined."
>
> A draft of C99 seems to say the same thing.
Yes. The real C99 do so too. I can't see that it leaves any hole open
for printing 0x000000 instead of 00000000 either (which IMHO would be
the sensible output). Some OS (Linux?, Sun?) I tried it on, did print
0x000000, thus my bad bug report.
> So I think this report can be closed.
Yes. Unless somebody says otherwise, I'll do that in some days.
Right,
MartinS
- Raw text -