Blocks in g++ ?
Per Bothner
bothner@pacbell.net
Fri Jun 11 15:56:00 GMT 1999
"Thomas Steffen" <for_replies_only@iname.com> writes:
> Per Bothner <bothner@pacbell.net> wrote:
> Per> (Creating closures is probably not practical unless you have
> Per> garbage collection.)
>
> that would explain why i have found only one case of closures in a
> compiler (one of the objective-C compilers, not gcc). could you
> explain why?
Closures are objects. (You can simulate objects using closures and
vice versa, fairly painlessly.) The problems is how to reclaim the
memory used by a closure if you are passing around a reference to
a closure object. I suppose you might be able to do it with reference
counting. But that means C++ has to know when it needs to adjust
closure references, which means it needs to know whetheer a pointer
is a reference to a closure or a pointer to a regular function.
I guess with some cleverness one would work out something that
works. I don't know of anyone having done so, though. Perhaps
its a cultural thing: People who want closures also want full
gcc, so it seems pointless to implement closures without gc.
Might make a nice Master's thesis project, though, or an useful
research paper.
--
--Per Bothner
bothner@pacbell.net http://home.pacbell.net/bothner/
More information about the Gcc
mailing list