How do I declare...

Chris Torek chris at umcp-cs.UUCP
Tue Aug 27 20:50:13 AEST 1985


It is interesting to note that recursive type definitions make
sense only for function pointers, and only because they have side
effects.  Defining (a pointer to)+ makes no sense, because you can
never do anything with it.  It only points.  You can do an infinite
number of indirections and it still just points.

With function pointers, however, indirecting through them causes
side effects; one such effect can be "terminate this program",
which is the magic clause that makes this useful.

Fascinating.

By the way, note that structure declarations such as

	struct foo {
		struct foo *next;
		...
	};

are not really recursive.  The inner entity is a pointer to struct
foo, not a struct foo.

Also by the way, the "most portable" declaration for (function
returning pointer to)+ is probably

	<type> *(*(*foo())())()

as this forces the function to return a pointer to a function that
returns a pointer; even if pointers to basic types are of different
sizes, most any compiler will have pointers to "pointer to function
returning pointer to <type>" being the same size as pointers to
"pointer to function returning pointer to function returning pointer
to <type>" and so forth.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 4251)
UUCP:	seismo!umcp-cs!chris
CSNet:	chris at umcp-cs		ARPA:	chris at maryland



More information about the Comp.lang.c mailing list