function returning pointer to itself
Scott M. King
smking at lion.waterloo.edu
Sun Jul 17 23:48:07 AEST 1988
In article <664 at goofy.megatest.UUCP> djones at megatest.UUCP (Dave Jones) writes:
>From article <7725 at watdragon.waterloo.edu), by smking at lion.waterloo.edu (Scott M. King): (me)
>) In article <5485 at batcomputer.tn.cornell.edu) olson at tcgould.tn.cornell.edu (olson) writes:
>))Does the new C standard have a natural way to declare a
>))function that returns a pointer to itself
>)
>) void *(*
>) main() )()
>) {
>) return main;
>) }
>)
>) Ugly eh???
>
>Ugly? Yes. Correct? No. Don't feel too bad, though.
Oh, don't worry, I don't feel too bad. My declaration *is* correct.
It declares a function returning a pointer to
a function returning a generic pointer.
However, you could just as easily have any number of levels of indirection
in such a declaration. Ie, the function could be declared as
a function returning a pointer to
a function returning a pointer to
... (any number of times)
a function returning a generic pointer (void *)
as in
void *(*(*(*(*(*(*(*(*main())())())())())())())())();
Or, the function could similarly be declared as
void *
main();
since you can quite easily convert any pointer to a void * and back without
loss of information.
--
Scott M. King
More information about the Comp.std.c
mailing list