Operating System - HP-UX
1755723 Members
3181 Online
108837 Solutions
New Discussion

Re: printf bug with '0' flag under HP-UX 11.11

 
SOLVED
Go to solution
vinc17
Occasional Visitor

printf bug with '0' flag under HP-UX 11.11

With printf under HP-UX 11.11 (hppa2.0w-hp-hpux11.11), the '0' flag is ignored when a negative precision argument is given, such as in

printf ("%05.*d\n", -1, 1);

The expected output is "00001", but under HP-UX, one does not get the 0's.

ISO C99 says in 7.19.6.1 ("The fprintf function"):

#5 A negative precision argument is taken as if the precision were omitted.

#6 For d, i, o, u, x, and X conversions, if a precision is specified, the 0 flag is ignored.

Note the difference between "precision" and "precision argument".

The reason of the above rule is that if a precision is specified, the number of leading 0's is already implied by the precision. Without this rule, there would be an inconsistency.

HP-UX seems to assume that a negative precision argument is like a given precision, thus ignores the '0' flag. But there are no reasons to ignore the '0' flag in this case: there is no explicit precision that fixes the number of leading 0's. Glibc (Linux), FreeBSD, NetBSD, OpenBSD and AIX all behave correctly.

This yields an error in the MPFR test suite.

1 REPLY 1
Steven Schweda
Honored Contributor
Solution

Re: printf bug with '0' flag under HP-UX 11.11

> With printf under HP-UX 11.11 (hppa2.0w-hp-hpux11.11), [...]

   Yup.  But you might have missed the window where anyone cares:

      https://h20195.www2.hpe.com/V2/getpdf.aspx/4AA4-7673ENW.pdf

> [...] all behave correctly.

its $ cc /version
HP C V7.3-020 on OpenVMS IA64 V8.4

its $ cc of
its $ link of
its $ run of
00001