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: [RFC]: designing customizable format attributes


On Tue, 12 Jul 2005, Ian Lance Taylor wrote:

> I considered that type of feature, and I'm certainly open to it.  I
> decided not to include it in my initial sketch because it is not
> necessary.  My goal for the little language was to keep it as simple
> as possible, and to express it straightforwardly in a single string.
> I don't anticipate many people will ever write these strings.  So for
> me the focus was on simplicity and lack of ambiguity.

I think maintainability of the printf/scanf/strftime/strfmon descriptions 
is a consideration, and for that you want more structure than a pure state 
machine.

> The width is irrelevant to the type to be matched.  So it's actually
> very easy to handle this ambiguity in the simple state machine I
> described.  After you see a number, if you then see a $ you go back to
> the state after seeing a '%'.  Otherwise you go to the state after
> seeing a field width.

You need to record that there was a field width (to check later whether 
it's OK for that format).  You don't really want to duplicate everything 
that follows in variants for width / no width.

> Looking at the code in c-format.c, I do see that the current code
> issues a warning for a zero field width.  To implement that with the
> simple state machine would be more tedious.  It would be necessary to
> introduce a way to emit a warning message, and have a state which
> represented "one or more 0 characters not followed by $".  I'm not
> sure where to balance simplicity of design and ease of use here.

There are lots of diagnostics for lots of things.  It's not simply a 
matter of emitting a type expected by a format specifier, various other 
information about the string (e.g. the flags present and whether they are 
duplicated) is collected at the same time.

-- 
Joseph S. Myers               http://www.srcf.ucam.org/~jsm28/gcc/
    jsm@polyomino.org.uk (personal mail)
    joseph@codesourcery.com (CodeSourcery mail)
    jsm28@gcc.gnu.org (Bugzilla assignments and CCs)


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