Mail Archives: djgpp-workers/2002/09/01/03:32:40
Hello.
DJ's Server wrote:
>
> This is an automatic daily mailing. If you have problems with it,
> send email to DJ at dj AT delorie DOT com
>
> 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.
So I think this report can be closed.
Bye, Rich =]
--
Richard Dawe [ http://www.phekda.freeserve.co.uk/richdawe/ ]
- Raw text -