This is the mail archive of the gcc-patches@gcc.gnu.org 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: Special handling of "%H" (Re: Support for %d$c format specifierin diagnostics.c)


Jonathan Lennox <lennox@cs.columbia.edu> writes:

> Zack Weinberg writes:
>> Phase 1: scan the string, build up an array of format specifiers
>> indexed by their %n$ number (if given) or position (if not).  This can
>> be done without communication with the language front end. For example:
>> 
>>     "too many arguments to %s `%+#D'"
>>     "too many arguments to %2$+#D the %1$s"
>> 
>> both produce the same array: { "s", "+#D" }.  For efficiency the array
>> elements should probably be { pointer, length } pairs with the pointers
>> pointing into the original string.  Ill-formed format strings -- mixed
>> explicit and implicit position, referencing the same argument twice
>> with different format codes, picking the wrong argument for the field
>> width or precision, leaving gaps in the list of referenced arguments --
>> can and should be diagnosed at this point.
>
> One problem with this algorithm: as near as I can tell from my reading of
> XSI printf, it's legal to use different field widths or flags for different
> references to the same positional parameter.

While this is true, I do not think it is worth worrying about.  I'm
extremely dubious about the value of referring to parameters more than
once with the %n$ notation.  I would rather a certain degree of
limitation on the format strings -- keep in mind that diagnostic.c
already does not implement all the features of standard C's printf --
if it enables us to use a simpler algorithm for the formatter.

zw


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