bug-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: implicit declaration of function 'yylex' is invalid in C99


From: Paul Eggert
Subject: Re: implicit declaration of function 'yylex' is invalid in C99
Date: Mon, 17 Jan 2022 10:15:49 -0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.3.1

On 1/17/22 02:07, Ryan Schmidt wrote:

How can I know whether these prototypes are the right ones or if they need to 
be different?

You look at the implementation of yylex and yyerror, and make sure the prototype declarations match the implementation's definition. Best practice is for the implementation to use the declarations, e.g. via '#include "y.tab.h"'.


Does a successful compile mean the prototypes were sufficiently correct?

If you follow best practice, yes. If not, not.


What about the static part? How would I have known that getdate.y needed the 
prototypes to be marked static? Or is that not needed there?

'static' means the functions are not visible outside the module defining them. This is often useful (though not required) when the functions are defined by the .y file and used only there.


What about the "int" return value of yyerror in getdate.y? Is that just a mistake and it 
should really be "void"?

Yes, pretty much. This is explained in the Bison manual.


conf.tab.c:1302:1: error: conflicting types for 'yyparse'
yyparse (struct config *conf)
^
conf.tab.h:116:5: note: previous declaration is here

This is because grok's #include order is messed up. conf.y includes conf.tab.h (which uses the type struct config) before it includes grok_config.h (which defines the type). C requires declaration before use, so it should include the files in the other order. Some compilers will go ahead and compile anyway, depending on their flags; others won't.


conf.tab.c:1495:23: error: too many arguments to function call, expected 0, 
have 2
       yychar = yylex (&yylval, &yylloc);

This is because the yylex declaration is missing. Add 'int yylex (YYSTYPE *);', preferably in an include file that both conf.lex and conf.y include so that they both agree with the declaration (this is the "best practice" I mentioned above).



reply via email to

[Prev in Thread] Current Thread [Next in Thread]