1
votes

I'm doing a project in C with Flex and Bison, but I found an error during the compile.

Here is the error:

A_Sintactico.yy:186:6: error: conflicting types for ‘yyerror’
In file included from A_Sintactico.yy:3:0:
A_Lexico.l:15:8: note: previous declaration of ‘yyerror’ was here
 extern yyerror(char*);
    ^

Code of yyerror in A_Sintactico.yy:

void yyerror(char* mens){
    extern int numlin;
    fprintf(stderr, "Error sintactico en la linea %i %s\n", numlin, mens);
}

Code of yyerror in A_Lexico.l

extern yyerror(char*);

What is happening?, Thanks!

2

2 Answers

1
votes

The correct declaration is

void yyerror(const char* mens);

And the function definition should be the same:

void yyerror(const char* mens) { … }

extern is not necessary, although it doesn't hurt. But the return type is obligatory.

Changing the argument to const char* is not necessary, but it is highly recommended, since yyerror may be called with a string literal as an argument.

0
votes

The extern version looks oldish. Implicit return is int in that case not void . You 'd have to get the two consistent.