I’m not sure if I am just blind but i get this dereferencing pointer to incomplete type in following code:
header:
enum foo {stuff1, stuff2, stuff3};
struct bar {
enum foo e;
int x;
int y;
};
file in which header is included:
void func(struct bar *b) {
switch(b->e) {
...
}
}
The error occures in the switch line, also code completion on b only offers me the ints x and y but not the enum.
When reading other people’s problems with this error I always see them using something at a point where it was not declared yet. But this is not the case here. So why does this code not compile?
It was asked for a complete example of the problematic code. So here it goes:
h-file:
enum commandType {ADD_TREE, DEL_TREE, //tree
ADD_NODE, DEL_NODE, //node
ADD_SEGM, DEL_SEGM, //segment
ADD_SKEL, MRG_SKEL, DEL_SKEL, //skeleton
ADD_BRCH, JMP_BRCH, //branchpoint
ADD_COMM, DEL_COMM, //comment
CHG_NODE, CHG_TREE //change active
};
struct SkelCommand {
enum commandType type;
int32_t id;
int32_t prevActiveId;
};
c-File:
struct stack *undoStack = NULL;
void undo() {
//popStack returns a void*
struct skelCommand *cmd = (struct skelCommand*) popStack(undoStack);
switch(cmd->type) {
case ADD_TREE:
break;
case DEL_TREE:
break;
case ADD_NODE:
break;
case DEL_NODE:
break;
case ADD_SEGM:
break;
case DEL_SEGM:
break;
case ADD_SKEL:
break;
case MRG_SKEL:
break;
case DEL_SKEL:
break;
case ADD_BRCH:
break;
case JMP_BRCH:
break;
case ADD_COMM:
break;
case DEL_COMM:
break;
case CHG_NODE:
break;
case CHG_TREE:
break;
}
}
in another c-file:
extern struct stack *undoStack;
void initialize() {
undoStack = newStack(4069);
}
Typo:
but the
structisSkelCommand, uppercaseS:Hence the error, as
struct skelCommandis an incomplete type.