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]

Re: cpplib: expression parser patch 2


On Sat, Apr 01, 2000 at 11:51:13PM +0900, Neil Booth wrote:
> Zack Weinberg wrote:-
> 
> > and possibly even clearer to write
> > 
> > #define SYNTAX_ERROR(message) \
> >   do { error(message); goto syntax_error; } while(0)
> 
> I'd like to do something like this.  However, does this cause a
> problem with internationalization?  I vaguely remember something about
> not being able to use _() gettext strings in a macro. 

Blargh.  Yes, there is a problem but I don't remember the precise
details.  The message _will_ be run through gettext at runtime; the
problem is the script that extracts messages from the source code.  It
might not find the message and put it into the .pot file.

It's pretty straightforward to test that.  Configure with
--enable-nls, do 'make gcc.pot', and grep for the messages in the
generated file (which lives in the source directory).  And I think it
will get it right if the macro argument name is "msgid".  Read
ABOUT-GCC-NLS and po/exgettext.

> Also, I'd like
> to be able to use varargs too, as I want to insert a "%s" in some
> error messages to tell the user which operator is causing a problem
> (possibly the next patch).  This might be a problem on many compilers
> I suspect.

Macro varargs are only possible with a GCC extension or with C99.
You'd have to have two macros, one that took an extra argument and one
that didn't.

 > I'm also considering
> 
> #define SYNTAX_ERROR(condition, message)\
>             do {\
> 	       error_str = message;\
> 	       if (condition)\
> 		 goto syntax_error;\
> 	     } while(0)
> 
> which has the disadvantage of a memory access / lost register to
> error_str, a procedure-local const char * variable, but the advantage
> of no jumps in the normal code path.  Opinions?

Benchmark it, or read the assembly dumps and see how much a difference
it makes.  Also, #if isn't performance critical, so you should be
asking: is that easier to read?

Oh, by the way, please put whitespace before a backslash-newline.

zw

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