Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site rtp47.UUCP Path: utzoo!watmath!clyde!bonnie!akgua!mcnc!rti-sel!rtp47!throopw From: throopw@rtp47.UUCP (Wayne Throop) Newsgroups: net.lang.c Subject: Re: How do I declare... Message-ID: <159@rtp47.UUCP> Date: Fri, 23-Aug-85 16:41:17 EDT Article-I.D.: rtp47.159 Posted: Fri Aug 23 16:41:17 1985 Date-Received: Sun, 25-Aug-85 14:04:32 EDT References: <368@persci.UUCP> Organization: Data General, RTP, NC Lines: 48 > Either I'm missing the perfectly obvious or I've found something > that's impossible to declare in C, even though it makes sense. You have discovered a fundamental flaw in C type notation. In essence, C allows recursive types only in structs, unions, and enums (and I'm not sure how it would be usefull in enums, so that one can be ruled out for practical purposes). Thus, if you want an array of pointers to arrays of pointers, you can't do it. Nor can you declare functions returning pointers to functions. It would be nice to be able to declare a recursive type, like so: typedef foo_type (*foo_type)(); ... foo_type foo; ... foo = (*foo)(); but this just doesn't work (on any compiler I ever heard of). You can do something like typedef struct foo_struct{ struct foo_struct (*dummy)(); } foo_type; ... foo_type foo; ... foo.dummy = (*foo.dummy)(); Another method is less portable but slightly more appealing (in terms of what is written to declare and use the recursive type). That is to use a cast at the appropriate points: typedef int (*foo_base_type)(); typedef foo_base_type (*foo_type)(); ... foo_type foo; ... foo = (foo_type)(*foo)(); which will fail if your compiler can't cast pointers-to-functions-returning-int into pointers-to-functions-returning-pointers-to-functions-returning-int, which doesn't seem very likely. In any event, all of these solutions are less pleasing than the possible alternatives that would exist if only fully recursive type declaractions were available in C. -- Wayne Throop at Data General, RTP, NC!mcnc!rti-sel!rtp47!throopw