forward references in typedefs
Henry Spencer
henry at utzoo.uucp
Fri Jul 21 01:29:35 AEST 1989
In article <55480 at tut.cis.ohio-state.edu> George M. Jones <george at cis.ohio-state.edu> writes:
>I have noticed what I consider anomolous behavior when using forward references
>in structs & typedefs and would would like to know whether things behave as
>they do because (a) that's just the way the compilers choose to implement
>a fuzzy point or (b) there is some definition (ansi, K&R) that say this is
>[in]correct behavior.
The latter. The language permits forward references with structure tags
(specifically, "struct foo *x;" when foo has not yet been seen) but not
the equivalent with typedefs. That's just the way it is.
(Oh, you want to know *why*? Basically, because typedefs are a royal pain
to parse at the best of times, and forward references just complicate the
issue hopelessly. That keyword "struct" on the front simplifies things
enormously. It also constrains the forward reference to be to a struct,
which makes things easier because although different types of pointers
sometimes have different representations [notably, the representation of
"char *" can differ from other pointers], it's very unusual for different
struct pointers to have different representations, so the compiler knows
how big a pointer it's got even if it's not quite sure what it points to.)
--
$10 million equals 18 PM | Henry Spencer at U of Toronto Zoology
(Pentagon-Minutes). -Tom Neff | uunet!attcan!utzoo!henry henry at zoo.toronto.edu
More information about the Comp.lang.c
mailing list