🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #4133

Re: Nested functions (was: Re: GOTO single exit point)

#4133
From: Wil Evers
Date: Thu, 28 Sep 1995 14:48
42 lines
2588 bytes
In article <449bs9$r8c@news0.rain.rg.net> Paul Long <plong@perf.com>  
writes:
> volpe@bart.crd.ge.com (Christopher R. Volpe) wrote:
> >In article <446ttn$deg@news0.rain.rg.net>, Paul Long <plong@perf.com>  
writes:
> >>In article <1995Sep25.114935.1575@ittpub>, Wil Evers <wil@ittpub.nl>
> >>writes:
> >>
> >>>- Use a different execution model for nested functions only. 
> >>>This is what most Pascal compilers do. In C, there would be major
> >>>problems in expressing pointers to such functions. We would need a
> >>>syntax to express a  'pointer to function nested in <this other
> >>>function>' or live with a big  loophole in the type system.
> >>
> >>Ugh. Some C compilers have this extension. These function pointers
> >>have a special operator (e.g., "!", I think) used to declared the
> >>pointer so that the compiler can generate different code for them.
> >
> >Ok, I'll bite: What happens if the nested function references auto
> >variables in the enclosing function, and then the nested function is
> >called through a function pointer when the enclosing function is not
> >active and said auto variable doesn't exist?
> 
> Currently, the value of a pointer to an automatic that is no longer
> guaranteed to be reserved is indeterminate. Likewise, referencing an
> automatic that is no longer reserved would result in undefined behavior.
> In other words, it does what you might think--your program runs off into
> the weeds. :-)

Please note that I did *not* suggest a special syntax for 'pointer to  
whatever nested function', but a special syntax for 'pointer to function  
nested in <this other function>'. By saying that, I meant that the  
enclosing function of the function pointed to should be a part of the type  
of the function pointer, so the compiler can do a check to make sure such  
a pointer is never used in a context where the locals of the enclosing  
function might do not exist. Basically, such a pointer would only be legal  
in the enclosing function and the functions it encloses. A pointer to a  
non-nested function would simply be the simplest of these: a pointer to a  
function nested in no other function, which is therefore legal everywhere  
in the program.

- Wil
Technical Details
Message-ID: <1995Sep28.144829.1579@ittpub>
Path: arc1-ca.pugleaf.net!EU.net!sun4nl!ittpub!ittpub!nntp
References: <449bs9$r8c@news0.rain.rg.net>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!EU.net!sun4nl!ittpub!ittpub!nntp
Newsgroups: comp.std.c
Subject: Re: Nested functions (was: Re: GOTO single exit point)
Message-ID: <1995Sep28.144829.1579@ittpub>
From: wil@ittpub.nl (Wil Evers)
Date: 28 Sep 95 14:48:29 WET
References: <449bs9$r8c@news0.rain.rg.net>
Distribution: world
Nntp-Posting-Host: beelzebub