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: c++/7765 [Patch]


bangerth@ticam.utexas.edu (Wolfgang Bangerth)  wrote on 28.10.02 in <Pine.LNX.4.44.0210281251240.736-100000@gandalf.ticam.utexas.edu>:

> > Yes, the order of formats must presently be preserved.  I realize that
> > this interferes with proper translation.  What we need to do is
> > implement the SVR4 "%1$x" printf extension: this allows you to write
> >
> >  msgid "statement about %d %s"
> >  msgstr "statement about %2$s in quantity %1$d"
> >
> > (I will get to this eventually, but the list of things I will get to
> > eventually has items on it from 1998, so don't hold your breath.
> > Patches for diagnostic.c are welcome.)
>
> Doing this first, before cleaning up what is there now, may be even
> the simpler way: about 1000 (half of the total) are ordering problems.
> These could, to a large extent, probably be fixed if the SVR4 syntax would
> be there, without even knowing the language in question. Maybe even
> semiautomatically.

Unfortunately, that's not exactly trivial. Maybe one could steal the  
relevant code from glibc?

Essentially, one would have to first build up a list of all specifiers in  
the format string, hope that that gives no holes with unused parameters in  
them where one does not know their type, then process the varargs with the  
type info one has into that list, and finally do another pass to output  
the whole mess - first and third pass in format string sequence, second  
pass in argument sequence.

It's not a particularly obvious piece of code. Actually, the glibc code is  
even worse IIRC because not only does it optimize the case where there are  
no n$ sequences (leading to a significantly different logic flow), it also  
IIRC tries do do several different printf variants with the same source -  
a macro jungle not quite like the worst places in gcc but definitely  
tending in that direction.

It is, however, possible to drastically clean it up by not trying to make  
it do just as much, which is what I did when reusing it for GNUstep (which  
does implement an additional %@ escape for objects which know how to  
generate a text description of themselves, incidentally; also uses its own  
locale system).

MfG Kai


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