incompletetype.c:6: error: dereferencing pointer to incomplete type.

时间:2022-07-14 16:31:45

http://*.com/questions/2700646/dereferencing-pointer-to-incomplete-type


What do you mean, the error only shows up when you assign? For example on GCC, with no assignment in sight:

int main() { struct blah *b = 0; *b; // this is line 6 }

incompletetype.c:6: error: dereferencing pointer to incomplete type.

The error is at line 6, that's where I used an incomplete type as if it were a complete type. I was fine up until then.

The mistake is that you should have included whatever header defines the type. But the compiler can't possibly guess what line that should have been included at: any line outside of a function would be fine, pretty much. Neither is it going to go trawling through every text file on your system, looking for a header that defines it, and suggest you should include that.

Alternatively (good point, potatoswatter), the error is at the line where b was defined, when you meant to specify some type which actually exists, but actually specified blah. Finding the definition of the variable b shouldn't be too difficult in most cases. IDEs can usually do it for you, compiler warnings maybe can't be bothered. It's some pretty heinous code, though, if you can't find the definitions of the things you're using.