#510819 glibc-doc-reference: wrong description of the '#' printf flag

#510819#5
Date:
2009-01-05 03:50:48 UTC
From:
To:
Conversion %#04hhx in printf means "convert the argument to a uint8_t (hh) and show it as an hexadecimal number (x) with leading zeros if necessary (0) and a leading 0x prefix (#) in a field of
total lenght four (4), that is, two places for 0x and two for the argument value".

If the argument is 0 the expected behaviour is to show 0x00 but it shows 0000

With other arguments it works ok.

#510819#10
Date:
2015-12-17 18:47:58 UTC
From:
To:
printf has the correct behaviour as the value 0 is a special case.
Quoting POSIX [1]:

| #
|     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. For x or X conversion
|     specifiers, a non-zero result shall have 0x (or 0X) prefixed to it.
|     For a, A, e, E, f, F, g , and G conversion specifiers, the result
|     shall 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
|     conversion specifiers, trailing zeros shall not be removed from the
|     result as they normally are. For other conversion specifiers, the
|     behavior is undefined.
|     0.

As you can see the '0x' prefix is added only for a non-zero value.
That is why '0000' is the correct output here.

I am therefore closing the bug.

[1] http://pubs.opengroup.org/onlinepubs/9699919799/functions/printf.html

#510819#15
Date:
2015-12-20 01:40:20 UTC
From:
To:
On Thursday, 17 de December de 2015 18:47:58 usted escribió:

Then, there is a bug in the documentation of the printf function.

Please fix it there.

Please, reopen and consider as a documentation bug.

#510819#20
Date:
2015-12-20 16:18:01 UTC
From:
To:
control: reassign -1 glibc-doc-reference
control: retitle -1 glibc-doc-reference: wrong description of the '#' printf flag
control: tag -1 + upstream

Indeed.

This mail should reopen the bug and reassign it to the
glibc-doc-reference package providing the documentation.

Aurelien