This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Support for %d$c format specifier in diagnostics.c

On Sat, 5 Jul 2003, Ishikawa wrote:

> Now, I am not entirely sure of the usage
> rule of %n$c format specifier.
> It seems to me ONCE we use the %n$ construct,
> we probably need to use this format from this point on always.
> (Or we need to use this form for ALL the format specifiers.)

It must be used for _all_ specifiers that convert arguments, or _none_ of
them.  (%% and %m, which don't convert arguments, can of course be mixed
with %n$.)  This includes width and precision specifications: if %n$ is 
used then *n$ must be used rather than plain * for getting width or 
precision from an argument (and vice versa).  Also, if the nth argument is 
used then all the previous ones must be since we otherwise don't know 
their types to get to the nth argument.  The relevant paragraph is:

     The format can contain either numbered argument conversion
     specifications (that is, "%n$" and "*m$"), or unnumbered argument
     conversion specifications (that is, % and * ), but 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.

I recommend aborting if either of these constraints isn't met at runtime,
at least if ENABLE_CHECKING.  (Once %n$ is implemented in diagnostic.c, a
possible future project would be to write a checker for the .po files that
makes sure that the source and translated strings are consistent, so that
bugs in them can be reported to the translation teams and fixed, rather
than waiting for someone to come across them at runtime.)

> 	Before setting, we should check the double definition
> 	(which is OK?) and incompatible double definition, etc..

It is OK to use the same argument more than once, provided that the same
type is used in each case (or a few other cases - formatting an argument
with both %1$d and %1$u would be OK if the value has zero sign bit - but I
don't think there's any need to allow such variations in diagnostic.c).
(In fact I doubt there's much use in GCC for using arguments multiple
times, and Bruce Korb has pointed out that glibc is broken with regard to
doing so.)

Joseph S. Myers

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]