Quote:
Originally Posted by
RudiC
Thanks for the reference. Even though it works as specified, it is not mentioned in the respective linux man page (although it is in FreeBSD).
It seems that some Linux developers update code to meet some POSIX requirements without taking the time to update the corresponding man page. (Do not read this as a slur against Linux; it happens in other development organizations too.)
It is a requirement in the POSIX description of the
printf utility (although it is not allowed in the
printf() family of C functions). From the 2016 edition (published by IEEE and The Open Group last week; still being balloted by ISO) of the POSIX standard
printf utility EXTENDED DESCRIPTION section on P3114, L101141-104149:
Quote:
The argument operands shall be treated as strings if the corresponding conversion specifier is b, c, or s, and shall be evaluated as if by the
strtod() function if the corresponding conversion specifier is a, A, e, E, f, F, g, or G.
Otherwise, they shall be evaluated as unsuffixed C integer constants, as described by the ISO C standard, with the following extensions:
- A leading <plus-sign> or <hyphen-minus> shall be allowed.
- If the leading character is a single-quote or double-quote, the value shall be the numeric value in the underlying codeset of the character following the single-quote or double-quote.
- Suffixed integer constants may be allowed.
The "otherwise" marked in red in the quote includes at least the d, o, and x conversion specifiers. And the bullet point marked in red is the requirement disedorgue's code relied upon. The requirement has been there since 1992, but in early versions of the standard, it was ambiguous as to whether or not the bullet point in red also applied to the floating-point conversion specifiers.