Newsgroups: comp.lang.c Path: utzoo!henry From: henry@utzoo.uucp (Henry Spencer) Subject: Re: forward references in typedefs Message-ID: <1989Jul20.152935.14872@utzoo.uucp> Organization: U of Toronto Zoology References: <55480@tut.cis.ohio-state.edu> Date: Thu, 20 Jul 89 15:29:35 GMT In article <55480@tut.cis.ohio-state.edu> George M. Jones 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@zoo.toronto.edu