|
Zefram |
at Oct 26, 2009 at 1:22 pm
|
⇧ |
| |
Dr.Ruud wrote:
After reading the above, I would expect
sprintf( "%+ d", 0 )
to return "0", but it returns "+0".
For your interpretation to be consistent, you'd have to expect that to
return " 0", i.e., space prefixed rather than unprefixed.
Is this a documentation or an implementation issue?
The documentation is in error: the "positive" should have been
"non-negative". Older versions of perlfunc(1) have "positive" instead of
"non-negative" in the descriptions of the individual flags too. POSIX is
clear (well, if you read it very carefully) that the flags affect zero:
+
The result of a signed conversion shall always begin with a sign
( '+' or '-' ). The conversion shall begin with a sign only when
a negative value is converted if this flag is not specified.
<space>
If the first character of a signed conversion is not a sign or
if a signed conversion results in no characters, a <space> shall
be prefixed to the result. This means that if the <space> and
'+' flags both appear, the <space> flag shall be ignored.
http://www.opengroup.org/onlinepubs/009695399/functions/printf.html-zefram