“warning: 'struct matrix' declared inside parameter list [enabled by default]” and error: conflicting types for 'scanToken'

前端 未结 1 829
时光说笑
时光说笑 2021-01-21 17:41

I\'ve been pouring over this issue trying to figure out what is causing these errors, but so far I\'ve come up with nothing. I have this function:

    struct tok         


        
1条回答
  •  面向向阳花
    2021-01-21 18:06

    You have to declare struct matrix outside a function prototype, like the error message implies.

    You have in your scanner.h header:

    struct token scanToken(struct matrix refTable);
    

    Since there's no prior declaration of struct matrix in that header, or a header read before it is read, the struct matrix is a new distinct type. It's also incomplete, so you really need to use a pointer to it.

    You can fix it as simply as:

    struct matrix;
    struct token scanToken(struct matrix *refTable);
    

    To be able to pass the struct matrix by value instead of by pointer, you need a full definition of the structure, but pointers can be passed to incomplete types.

    Or include the header that defines the struct matrix fully in the scanner.h header.

    Note that you should protect your headers with multiple inclusion guards:

    #ifndef SCANNER_H_INCLUDED
    #define SCANNER_H_INCLUDED
    
    …current contents…
    
    #endif // SCANNER_H_INCLUDED
    

    You might well add #include "otherheader.h" in that one — the other header that defines struct matrix in full.

    0 讨论(0)
提交回复
热议问题