Le 23 janv. 2012 à 11:57, Jim Meyering a écrit : > Hi Akim, > > How about this?
Actually, for mhistorical reason, yyerror is really expected to return an int (by default, which is the case here). I guess it dates back to the good ol' time o' C when not declaring was fine, and meant int. http://pubs.opengroup.org/onlinepubs/7908799/xcu/yacc.html > The following functions appear only in the yacc library accessible through > the -l y operand to cc or c89; they can therefore be redefined by a portable > application: > int main(void) > This function will call yyparse() and exit with an unspecified value. Other > actions within this function are unspecified. > int yyerror(const char *s > This function will write the NUL-terminated argument to standard error, > followed by a newline character. > I didn't find anyone using the return value, so rather than > trying to preserve semantics for nonexistent callers, I opted > to make this yyerror function return void as documented. What do you mean by "as documented"? > > Oh, wait! > I do see one non-void use. It's in data/glr.c: > > return yyerror (]b4_yyerror_args[YY_("syntax error: cannot back up")), \ > > From the context, I'm not sure if that code is ever used: > > ------------------------------------------ > # undef YYBACKUP > # define YYBACKUP(Token, Value) > \ > return yyerror (]b4_yyerror_args[YY_("syntax error: cannot back up")), > \ > yyerrok, yyerr I don't see what you mean here: the return value is ignored by ','. > Anyhow, with that I'm not so sure it's ok to s/int/void/. I don't think it is. But there is no semantics attached to that int. 0 would do fine. > * lib/yyerror.c (yyerror): Use fputs and fputc rather than fprintf > with a mere "%s\n" format. Also, change the return type to void. > This avoids a problem reported by Thiru Ramakrishnan in > http://lists.gnu.org/archive/html/help-bison/2011-11/msg00000.html > --- > lib/yyerror.c | 7 ++++--- > 1 files changed, 4 insertions(+), 3 deletions(-) > > diff --git a/lib/yyerror.c b/lib/yyerror.c > index 5eb339f..5ac0438 100644 > --- a/lib/yyerror.c > +++ b/lib/yyerror.c > @@ -20,10 +20,11 @@ > #include <config.h> > #include <stdio.h> > > -int yyerror (char const *); > +void yyerror (char const *); > > -int > +void > yyerror (char const *message) > { > - return fprintf (stderr, "%s\n", message); > + fputs (message, stderr); > + fputc ('\n', stderr); > } So you are engaging yourself gnulib will never #define these guys? :) Actually, is main.c's setlocale's also protected from such dependencies? > #include <config.h> > > #if HAVE_LOCALE_H > # include <locale.h> > #endif > #if ! HAVE_SETLOCALE > # define setlocale(Category, Locale) > #endif > > int yyparse (void); > > int > main (void) > { > setlocale (LC_ALL, ""); > return yyparse (); > }
