Re: fmtcheck.c
Re: fmtcheck.c
- Subject: Re: fmtcheck.c
- From: Steve Checkoway <email@hidden>
- Date: Sat, 2 Jul 2005 14:03:13 -0700
On Jul 2, 2005, at 1:14 PM, Markus Hitter wrote:
'f' means float. %f == %lf is a implementation detail of the
Darwin. This wasn't always the case.
Perhaps it wasn't always the case but the ISO/IEC 9899:1999 (E)
standard says of the l(ell) length modifier:
Specifies that a following d, i, o, u, x or X conversion specifier
applies to a long int or unsigned long int argument; that a following
n conversion specifier applies to a pointer to a long int argument;
that a following c conversion specifier applies to a wint_t argument;
that a following s conversion specifier applies to a pointer to a
wchar_t argument; or has no effect on a following a, A, e, E, f, F,
g, or G conversion specifier.
The linux man page for printf(3) says that the C99 standard does not
include the style using '$'--and indeed, I could not find it--but
says that it comes from the Single Unix Specification.
On this point, the Linux and BSD man pages differ. The BSD man page
says, "If unaccessed arguments in the format string are interspersed
with ones that are accessed the results will be indeterminate."
The Linux man page says, "If the style using ‘$’ is used, it must be
used throughout for all conversions taking an argument and all
width and precision arguments, but it may be mixed with ‘%%’
formats which do not consume an argument. There may be no gaps in
the numbers of arguments specified using ‘$’; for example, if
arguments 1 and 3 are specified, argument 2 must also be specified
somewhere in the format string."
It's clear that the Linux man page has a strong requirement since "%2
$d %d %1$d" would be allowed by the BSD page, it would not be allowed
by the Linux page. ("%2$*d" is disallowed by both man pages.)
Given the discrepancy, the only thing to do was to check the Single
Unix Specification (http://www.opengroup.org/onlinepubs/007908799/xsh/
fprintf.html) which has this to say:
The format can contain either numbered argument specifications (that
is, %n$ and *m$), or unnumbered argument specifications (that is, %
and *), but normally not both. The only exception to this is that %%
can be mixed with the %n$ form. The results of mixing numbered and
unnumbered argument specifications in a format string are undefined.
When numbered argument specifications are used, specifying the Nth
argument requires that all the leading arguments, from the first to
the (N-1)th, are specified in the format string.
This appears to agree with the Linux man page with the exception that
it says that the only exception to the rule about not mixing argument
types is mixing %n$ with %% but does not say anything about mixing *m
$ with %%. I can only assume that that omission is unintentional and
that the latter is allowed.
I'll fix my code shortly.
- Steve
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden