C compiling: “defined as wrong kind of tag”

Just to help people who face this problem: If you’re compiling your C code, and then the compiler says to you something like this:


./foo.c: In function `bar':
./foo.c:158: `structure_x' defined as wrong kind of tag

Don’t panic! Take a look at the bar function.

You’re probably declaring a variable of the structure_x kind but as a different type it really is.

For example, structure_x is an enum and you did something like this:

struct structure_x my_variable;

when the correct would be:

enum structure_x my_variable;.

This post is simple, but will surely help to avoid headaches :P