Reputation: 2866
I am implementing a struct
in C:
typedef struct {
...
} _p_TSResilOnline;
typedef struct _p_TSResilOnline *TSResilOnline;
After (in the same file), I am using:
TSResilOnline o = (TSResilOnline)(chk->data);
...
*check = (o->threshold < PetscAbs(sf)) ? PETSC_FALSE : PETSC_TRUE;
But my compiler returns:
error: incomplete definition of type 'struct _p_TSResilOnline'
*check = (o->threshold < PetscAbs(sf)) ? PETSC_FALSE : PETSC_TRUE; ~^ note: forward declaration of 'struct _p_TSResilOnline' typedef struct _p_TSResilOnline *TSResilOnline;
I am wondering what is incomplete. The compiler should know everything.
Upvotes: 0
Views: 1118
Reputation: 310950
In this declaration
struct {
...
} _p_TSResilOnline;
you defined an object with identifier _p_TSResilOnline
that has type of an unnamed structure.
In this declaration
typedef struct _p_TSResilOnline *TSResilOnline;
you declared structure type struct _p_TSResilOnline
.
The identifier _p_TSResilOnline
of the object and identifier _p_TSResilOnline
used to name the structure in the typedef declaration are in different namespaces and identifies different entities.
The definition of struct _p_TSResilOnline
is incomplete because members of the structure are unknown.
However in this expression
o->threshold
you are trying to access member with name threshold
that was not declared.
So the compiler issues an error.
EDIT: After you changed the first declaration in your question the following way
typedef struct {
...
} _p_TSResilOnline;
nevertheless again _p_TSResilOnline
and struct _p_TSResilOnline
are different entities and their identifiers belong to different name spaces.
You should write instead
struct _p_TSResilOnline {
...
};
or
typedef struct _p_TSResilOnline {
...
} _p_TSResilOnline;
Upvotes: 2