Search code examples
cstructtypedefheader-files

Probably bad using structures and typedef in header


Hello how to rewrite probably bad construction?
I tryed to ask how to fix it to make it work there,but maybe it's all the bad conception. Any other solution to do that? It's compiled in Eclipse using GCC for linux, compiled as C code.

file first.h

#ifndef FIRST_H_
#define FIRST_H_

typedef struct foo
{
    int a;
    char *c;
} foo_struct;

#endif /* FIRST_H_ */

file second.h:

#ifndef SECOND_H_
#define SECOND_H_

#include "first.h"

typedef struct wtf
        {
        foo_struct *poleFOO[5];
        }wtf_struct;

#endif /* SECOND_H_ */

Concretely in file second.h row foo_struct *poleFOO[5]; throws: "foo_struct could not be resolved" I work on Linux Ubuntu 11.10 using gcc in editor Eclipse for C and C++.


Solution

  • Okay, this is not an error from the compiler but from Eclipse. Simply Googl'ing the error "could not be resolved" points me to articles talking about Eclipse CDT (the eclipse subsystem for C/C++ development).

    So it has something to do with Eclipse, your C headers look syntactically right. I believe that without a C file but only headers, Eclipse does not know how to parse the headers only to create its own index database (must be used for intellisense, symbols list, etc.)

    I suggest you insert a simple C file including second.h, and with a main() function so that the link step passes as well, for example:

    #include "second.h"
    
    int main() {
        wtf_struct my_variable;
        return 0;
    }