typedef in c

ark at rabbit.UUCP ark at rabbit.UUCP
Sun Dec 18 01:07:08 AEST 1983


Original query:  Why doesn't this work:

	typedef struct {
		newtyp *link;
	} newtyp;

Answer:  C is, in effect, a language designed to be parsed
in a single pass.  In the example above, the compiler doesn't
even know yet that "newtyp" is a type the first time it encounters
it, so it can't parse it.  The following will work, though:

	struct newtyp {
		struct newtyp *link;
	};

or even:

	typedef struct foo {
		struct foo *link;
	} newtyp;

because in each case there are no forward references necessary to work
out the meaning of an identifier.



More information about the Comp.lang.c mailing list