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 specifier in diagnostics.c)


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.  For instance, on Solaris, the
program

#include <stdio.h>

char* str = "Hello!";

int main()
{
  printf("%1$.1s\n%1$.2s\n%1$.3s\n%1$.4s\n%1$.5s\n%1$.6s\n", str);

  return 0;
}
produces the output
H
He
Hel
Hell
Hello
Hello!

I don't know if anyone would actually want to do this in GCC's translations,
but I wouldn't totally rule it out.

-- 
Jonathan Lennox
lennox at cs dot columbia dot edu

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