Article View: comp.std.c
Article #5205Re: function returning pointer to itself
From: Dave Jones
Date: Mon, 18 Jul 1988 01:42
Date: Mon, 18 Jul 1988 01:42
57 lines
2014 bytes
2014 bytes
From article <7797@watdragon.waterloo.edu>, by smking@lion.waterloo.edu (Scott M. King):
> In article <664@goofy.megatest.UUCP> djones@megatest.UUCP (Dave Jones) writes:
>>From article <7725@watdragon.waterloo.edu), by smking@lion.waterloo.edu (Scott M. King): (me)
>>) In article <5485@batcomputer.tn.cornell.edu) olson@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.
>
[Incorrect correctness argument omitted.]
>
At the risk of starting a "'Tis. 'Tain't" kind of argument, I must
respectfully state "Tain't."
Here's what the Sun3 4.3 C compiler says, yanked dircectly with
the "put" and "get" keys:
"foo.c", line 4: warning: illegal pointer combination
Someone -- I'm regret that I have discarded the letter, and cannot
recall his name -- pointed out that you *can* declare a function that
returns a *structure* containing a pointer to the function, as follows:
typedef struct ugly {
struct ugly (*pf)();
} fptUG;
fptUG
main()
{
fptUG retval;
retval.pf = main;
return retval;
}
As I pointed out in the first response, the "struct" name-space
is the only one which allows for forward reference.
He said that the above solution was close enough for him. Well, okay,
I'll go along with it, although I don't know what "struct ugly" has to
do with anything.
-- Dave J.
Technical Details
Message-ID:
<667@goofy.megatest.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!attcan!uunet!husc6!purdue!decwrl!megatest!djonesReferences:
<7797@watdragon.waterloo.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!husc6!purdue!decwrl!megatest!djones From: djones@megatest.UUCP (Dave Jones) Newsgroups: comp.std.c Subject: Re: function returning pointer to itself Message-ID: <667@goofy.megatest.UUCP> Date: 18 Jul 88 01:42:39 GMT References: <7797@watdragon.waterloo.edu> Organization: Megatest Corporation, San Jose, Ca Lines: 57