This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Pointer to undeclared structure-type considered ok?
Hi Nick,
>In what sense is the "struct bar" type defined?
None.
I did not say that the "struct bar" type is defined.
It's also not used or referenced.
>Because if "struct bar" is not defined, then how can "struct bar *" be
defined?
The definition of "struct bar*" is not dependent upon the definition of
"struct bar".
Pointers are fundamental data types.
>Is it ok to to have pointer-type whose base type is not (or incompletely)
defined?
Assuming you are using "base type" in a contextually liberal sense for
"reference type", instead of the inheritance sense of C++...
Yes, it's ok -- for a lot of operations. What you are dealing with is a
pointer. A pointer is a fundamental data type.
What you cannot do is increment/decrement the pointer, use array access, or
access the (undefined, unknown) members, or dereference the pointer in any
other fashion[1].
--Eljay
[1] Well, you can dereference it using casting techniques to a defined,
known type. But that's slight-of-hand.