Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!amdcad!light!bvs From: bvs@light.uucp (Bakul Shah) Newsgroups: comp.lang.c++ Subject: Re: More nits to pick at... Keywords: self-reference Message-ID: <1989May2.192434.23371@light.uucp> Date: 3 May 89 02:24:32 GMT References: <190@riunite.ACA.MCC.COM> <9279@alice.UUCP> <193@riunite.ACA.MCC.COM> Reply-To: bvs@light.UUCP (Bakul Shah) Organization: /etc/organization Lines: 30 In article <193@riunite.ACA.MCC.COM> rfg@riunite.UUCP (Ron Guilmette) writes: >>How can you declare a function which can accept a pointer >>to itself as an argument (in a type-safe manner of course)? >> >> You can't in C++ or C. > >Well, so is anybody (other than me) concerned about this? A small extension to C can fix this: allow *forward* declaration of a type name. A later full declaration will complete the definition. typedef foo; /* forward declaration of type foo */ typedef int (*foo)(foo); /* it is a type `function (foo) returning int' */ int fun(foo f) { ... } main() { printf("%d\n", fun(fun)); } Extending an existing compiler to recognize this may not be easy though. -- Bakul Shah <..!{ucbvax,sun,uunet}!amdcad!light!bvs>