🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.misc
Article #2604

Re: On whether C has first-class composable functions

#2604
From: Karl Heuer
Date: Mon, 07 Jan 1991 04:57
32 lines
2054 bytes
In article <1991Jan6.171234.27734@d.cs.okstate.edu> norman@d.cs.okstate.edu (Norman Graham) writes:
>From article <1991Jan05.222639.6387@dirtydog.ima.isc.com>, by karl@ima.isc.com (Karl Heuer):
>>I disagree.  Since the return value of the function references objects that
>>go out of scope before the value would be used, I would expect this to
>>analogous to   int *h(int i) { return &i; }   , which is undefined.

>names have scope--values do not.

True.  I should have said "storage duration".

>[The example should work, since it uses the *values* of f and g.]

It's not f and g that are being used beyond their storage duration, it's the
anonymous function itself.  If C had Pascal-like nested functions, like
	int beta(int x) {
	    int alpha(void) { return x; }
	    return alpha();
	}
I would consider "alpha" to be an object of type function that has automatic
storage duration, and hence becomes invalid when it goes out of scope.  So
	int (*gamma(int x))(void) {
	    int alpha(void) { return x; }
	    return &alpha;
	}
is illegal for the same reason as my earlier example.  Making alpha an
anonymous function does not change the situation.

Of course, you can also consider a further extension in which functions are
allocatable; but I was rebutting the statement "you cannot add unnamed
functions in a natural way without getting the additional semantic power".

Karl W. Z. Heuer (karl@ima.isc.com or uunet!ima!karl), The Walking Lint
Technical Details
Message-ID: <1991Jan07.045733.13637@dirtydog.ima.isc.com>
Path: arc1-ca.pugleaf.net!utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!clyde.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!mintaka!spdcc!ima!dirtydog!karl
References: <1991Jan05.222639.6387@dirtydog.ima.isc.com> <1991Jan6.171234.27734@d.cs.okstate.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!clyde.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!mintaka!spdcc!ima!dirtydog!karl
From: karl@ima.isc.com (Karl Heuer)
Newsgroups: comp.lang.misc
Subject: Re: On whether C has first-class composable functions
Message-ID: <1991Jan07.045733.13637@dirtydog.ima.isc.com>
Date: 7 Jan 91 04:57:33 GMT
References: <1991Jan05.222639.6387@dirtydog.ima.isc.com> <1991Jan6.171234.27734@d.cs.okstate.edu>
Sender: news@dirtydog.ima.isc.com (NEWS ADMIN)
Organization: Interactive Systems
Lines: 32