I have a few structures with cross-pointers in my program, they are defined like this:
typedef struct
{
...
struct myvar *next;
struct myvar *prev;
...
} myvar;
typedef struct
{
...
myvar *first;
...
} variables;
And I am getting a strange error on the next piece of code:
variables *Variables;
...
Variables->first->prev->next = Variables->first;
I am using MS Visual Studio, and it says
error C2037: left of 'next' specifies undefined struct/union 'myvar'
I have set it to Compile as C Code (/TC), in C++ mode all is ok. What is the problem and is there some workaround except something like this?
tmp = Variables->first->prev;
tmp->next = Variables->first;
I constantly run into these problems, too 🙂 Forward-declaring your typedefs should help you in your situation: