Let's say I have this C code that has two different declarations in C.
struct pcdata
{
int x; int y;
};
int yyparse (struct pcdata *pp);
int yyparse (void *pp);
int yyparse (struct pcdata *pp)
{
}
Compiling the code with cc/gcc, I have conflicting types
error.
test> cc -c hello.c
hello.c:7:5: error: conflicting types for 'yyparse'
int yyparse (void *pp);
^
hello.c:6:5: note: previous declaration is here
int yyparse (struct pcdata *pp);
^
1 error generated.
test> gcc -c hello.c
hello.c:7: error: conflicting types for ‘yyparse’
hello.c:6: error: previous declaration of ‘yyparse’ was here
There is no error with g++ as c++ allows function overloading.
test> g++ -c hello.c
Is there any gcc option to allow function overloading? I have this (simplified) code with Bison 2.7 generated tab.c code.
That certainly won't work in C, but it shouldn't be necessary.
bison normally creates a yyparse
which takes no arguments at all, but you can use the %parse-param
declaration (at least in versions of bison which are not too old) to tell bison what arguments you want it to take.
In all cases, there is only one yyparse
unless you have two separate parsers compiled into the same program, which of course can happen when you have more than one grammar which needs to be parsed. In this case, you can use %name-prefix
to tell bison that one or both of the bison-generated parsers should use a prefix other than yy
.