Re: [PATCH 1/1] lib/vsprintf.c: "%#o",0 becomes '0' instead of '00'

From: Stephen Rothwell
Date: Sun May 06 2012 - 23:56:12 EST


Hi Pierre,

On Mon, 7 May 2012 04:20:18 +0200 Pierre Carrier <pierre@xxxxxxxxxxx> wrote:
>
> On Mon, May 7, 2012 at 3:59 AM, Joe Perches <joe@xxxxxxxxxxx> wrote:
> > If you do this, why not change 0-7 instead of just 0?
>
> Consistency with POSIX *printf.
>
> "#: 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 zero."
> -- http://pubs.opengroup.org/onlinepubs/009695399/functions/printf.html
>
> % cat octal.c;gcc -o octal octal.c;./octal
> #include <stdio.h>
> void main() {
> int i;
> for (i=0;i<10;i++) printf("%#o ", i);
> puts("");
> }
> 0 01 02 03 04 05 06 07 010 011

Yes, if we are going to follow anything, then it may as well be that.

However just to add more mess, the next part of that section of the standard says:

"For x or X conversion specifiers, a non-zero result shall have 0x (or
0X) prefixed to it."

so we should also do:

0 0x1 ...

However, I think we expect 0x0, so changing it is, I think, unnecessary.

--
Cheers,
Stephen Rothwell sfr@xxxxxxxxxxxxxxxx
http://www.canb.auug.org.au/~sfr/

Attachment: pgp00000.pgp
Description: PGP signature