假设我有这个 C 代码,它在 C 中有两个不同的声明。
struct pcdata
{
int x; int y;
};
int yyparse (struct pcdata *pp);
int yyparse (void *pp);
int yyparse (struct pcdata *pp)
{
}
用 cc/gcc 编译代码,我有conflicting types
错误。
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
g++ 没有错误,因为 c++ 允许函数重载。
test> g++ -c hello.c
是否有任何 gcc 选项允许函数重载?我有这个(简化的)代码和 Bison 2.7 生成的 tab.c 代码。