Dereferencing a pointer to incomplete type
NickName:Chris Ask DateTime:2013-03-22T09:34:19

Dereferencing a pointer to incomplete type

Let's say we have two structs in a source file:

struct B {
    int x;
};

struct A {
    beta y;
}; 

In the equivalent header file we have these:

typedef B* beta;
typedef A* alpha;

Also, these function prototypes are defined at the header file:

printAplha(alpha);
compare(const beta, const beta);

In the main file, I have included the specific header file and the code looks like this:

alpha one, two;
printAlpha(one);
printAlpha(two);
//everything works fine up to here
compare(one->y, two->y);

At the last line of the code I am getting

main.c:37:20: error: dereferencing pointer to incomplete type
main.c:37:33: error: dereferencing pointer to incomplete type

I know I can use a wrapper function for compare, the arguments of which would be of type alpha (as the arguments of the compare function cannot be changed - it's a recursive one), but I would like to see if there is any other solution, and why is this happening.

Note: The struct definitions have been written into the source file for creating an opaque data type.

Copyright Notice:Content Author:「Chris」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/15561242/dereferencing-a-pointer-to-incomplete-type

Answers
Tuxdude 2013-03-22T01:58:51

You're trying to declare an opaque data-type for struct A and struct B using the typedefs, but at the same time you're trying to access the fields using such an opaque type.\n\nYou can only do one of the above, not both simultaneously.\n\nThe solution is to either expose the complete struct definition or provide helper methods which will help access the specific fields. The implementation of the helper methods will again need to have access to the complete structure definition.",


More about “Dereferencing a pointer to incomplete type” related questions

Dereferencing Pointer to incomplete type

I've been at this for a couple hours and can't figure out this probably stupid mistake. Here are the errors: crawler.c:8: error: dereferencing pointer to incomplete type crawler.c:9: error:

Show Detail

dereferencing pointer to incomplete type (radix tree)

I'm having major trouble with my struct definition. I have tried a couple different ways of defining them but can't seem to get rid of the error. I probably also have a wealth of other problems wi...

Show Detail

Dereferencing a pointer to incomplete type

Let's say we have two structs in a source file: struct B { int x; }; struct A { beta y; }; In the equivalent header file we have these: typedef B* beta; typedef A* alpha; Also,

Show Detail

"Dereferencing Pointer to Incomplete Type" in provided code

I am trying to write a program using code given to me by the author of my textbook, but I am getting "Dereferencing Pointer to Incomplete Type" errors in every method when trying to compile a program

Show Detail

dereferencing pointer to incomplete type in C

The function getManager creates a Manager struct and returns a pointer to it from the type ManagerP (This function works ok). The definitions are like this : typedef struct Manager { int ID; char ...

Show Detail

dereferencing pointer to incomplete type in C code

I called the below function passing a struct pointer. I'm getting the error "dereferencing pointer to incomplete type" where ever I pointed currentTableItem -> Please help.

Show Detail

Dereferencing pointer to incomplete type (nodes)

Hey so I'm getting that error whenever I try to do something like this: void swap(struct lnode* n1){ struct lnode*temp = n1->next; } I thought that I could have the temp pointer point to n1->

Show Detail

dereferencing pointer to incomplete type|

this is my header file #include<stdio.h> #include<stddef.h> char memory[25000]; //Declare an array of 25000 bytes in size //Define data structure to save the details of the each

Show Detail

C error: dereferencing pointer to incomplete type, struct

I know this question is asked tons of times, but I cannot seem to link it to my problem. My problem is something to do with filling out a web of structs Here is my buggy code src\fpu.c:17:7: err...

Show Detail

dereferencing pointer to incomplete type

i'm trying to implement tree structure in c: this part is from the header file: typedef struct SP_Tree_Node { char * value; struct Node * children; int indexOfLastChild; } Node; type...

Show Detail