Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!uwm.edu!rpi!crdgw1!uunet!munnari.oz.au!csc!ccadfa!usage!troy@mr_plod.cbme.unsw.oz From: troy@mr_plod.cbme.unsw.oz (Troy Rollo) Newsgroups: comp.lang.c Subject: Re: on the fringe of C syntax/semantics Message-ID: <453@usage.csd.unsw.oz> Date: 5 Oct 89 04:30:36 GMT References: <80100001@bonzo> Sender: news@usage.csd.unsw.oz Reply-To: troy@mr_plod.cbme.unsw.oz Lines: 38 From article <80100001@bonzo>, by roy@bonzo.sts.COM: roy> cake, but how about a good, general declaration for a function? roy> '(int *())' and '(int ())' were two tries at declaring a general function roy> that returns an 'int', but they didn't work. Are you stuck with roy> something like '(int (*foo)())', where 'foo' is a particular function Strictly, there's no legal way of doing this..... Hang on, yes there is: typedef int (*function)(); Then when you're putting it in the code, user (function) as your type cast. This isn't really on the edge of the language specs.... although I ran into a question last night which was... somebody wanted to define a pair of structures which were initialised with pointers to eachother. Fine, except that one hasn't been defined - no address because no space is allocated, and the compiler doesn't have the faintest idea what you're on about until later, when you declare the second structure. The solution was to effect a forward declaration by using the extern keyword. This causes the problem to be passed off to the linker, which resolves the external reference - from the same file! struct a_struct { void *next; int value; }; struct b_struct { struct a_struct *next; int value; }; extern struct b_struct struc2; struct a_struct struc1 = { &struc2, 0 }; struct b_struct struc2 = { &struc1, 0 }; ___________________________________________________________ troy@mr_plod.cbme.unsw.oz.au Make our greenies useful! The Resident Fascist Put them in the army!