Undeclared identifier with definition in header file

212 Views Asked by At

include "spinach.h" is included in the main.c file

main.c makes a function call to a struct defined in spinach.h header. The function call occurs in the main.c function, and is the first reference to this type Lexer. The main.c file runs without error absent this line.

  Lexer *lex = malloc(sizeof(Lexer));

The definition is on the 0 indentation level (it is not defined in local scope); it is given below in triple quotes. In the header (spinach.h)

typedef struct {
  char **lines;
  char* current;
  int pos;
  int line;
  int col;

  int* indentlevel;
  int indentcap;
  int indentlen;
} Lexer;

What happpens?

 bash run.sh
main.c:115:3: error: use of undeclared identifier 'Lexer'
  Lexer *lex;
  ^
main.c:115:10: error: use of undeclared identifier 'lex'
  Lexer *lex;
         ^
2 errors generated.

Any variation that includes Lexer, including using pointers, references to malloc or the output of a custom initializer function will throw related errors.

Looked for multiple references (same global variable in 2 files in main.py references) to Lexer. All references on the internet are examples wherein the header file is not included, the variable or function is defined after the reference or call, or is absent entirely, else the error will show where there shows a reference in a global scope to a local definition. I do not see this to be the case. All references to custom struct lever in the main.c file, main function will throw this error. If the definitions are placed in the main.c file itself, instead of the header spinach.h referenced, it runs without error.

0

There are 0 best solutions below