"Rob Jackson" <ma********@lineone.net> wrote in message
news:95**************************@posting.google.c om...
HiI've got a struct, known by file A.c, which contains a pointer to
struct B. Struct B is unknown by file A.c (it is declared in C.h), and
contains a typedef enum, which is declared in a file B.h, which is
included in file A.c
(this is getting really confusing, I know!).
Yes, which is why it's always better to post example code
to illustrate your question. However, I'll take a guess.
See below.
I
want to access the enum in file A.c, but don't want to include file
C.h, for various reasons.I've tried casting the enum, but still get
the error "Dereferencing pointer to incomplete type.
"Example://fileA.c<#include> "fileB.h"struct a *a_struct; if
(a->b->typedefed_enum == enum_VALUE)////fileB.htypedef enum
{enum_VALUE, enum_OTHER } enum_type; //If this actually makes sense
(I've reread it, and can just about get my head around it!), has
anyone got any ideas how to cast it? (or do anything else to access
it).I've tried if ((enum_type) a->b->typedefed_enum == enum_VALUE
)but to no avail.
As a result of whatever organizational machinations you're
using with your source files, it seems that you're trying
to tell the compiler to dereference a pointer to a struct
whose complete definition it has not yet parsed. This is
what it means by *incomplete type*. The declaration of
a pointer to an incomplete type is allowed, but the dereference
of such a pointer requires the full type be known, otherwise
not enough information is availabe to identify the actual
type of object resulting from the dereference. Was *that*
confusing? :-)
int main()
{
struct X *p; /* OK, don't need to see 'inside' struct X */
p->a; /* Not OK, what is 'a'? */
return 0;
}
/* in a header or somewhere else not yet parsed */
struct X
{
int a;
};
You need to ensure that the full definition of the struct
is visible at the point you refer to its members.
Well, that's my best guess as to your problem. If you
post a short example demonstrating it, perhaps we can
give a more definitive analysis.
-Mike