[Gc] C++ API enhancement proposal

Boehm, Hans hans.boehm at hp.com
Fri May 11 10:33:59 PDT 2007


> From: g skaller
> Sent: Friday, May 11, 2007 12:35 AM
>
> On Fri, 2007-05-11 at 08:48 +0200, Christophe Meessen wrote:
> 
> > add in gc_cpp.cpp
> > 
> >    struct GC_initializer { GC_init_struct() { GC_INIT(); } }
> >    GC_initializer gc_initializer;
> > 
> > Note: it won't completely eliminate the problem of global instance 
> > initialization alloacting blocks because we can't ensure libgc is 
> > initialized first.
> 
> Yes, and it's a bad idea for that reason. It's important to 
> delegate the responsibility to the programmer BECAUSE there 
> is no safe automatic solution.
> 
I'm not much in favor of this solution either.  It was used in the C
code (with the gcc constructor attribute) at some point, and
subsequently backed out.  My (limited) experience with static C++
constructors like this has been pretty uniformly negative.  They work
for a while, and as the project grows, eventually something changes, and
they run in the wrong order, and create a difficult debugging problem.
My understanding is that some well-known companies have coding
guidelines prohibiting them.

In response to this discussion, I did just add a couple of assertions to
make this kind of problem easier to diagnose, at least if you think of
building the collector with assertions enabled.

> 
> > Better than nothing, in wait of gc support in C++.
> 
> C++ will never have gc support: C++ isn't compatible
> with garbage collection.
> 
> Bjarne tried to get this into the first version of the 
> Standard, but wasn't able to come up with a satisfactory 
> proposal. This is not surprising, there simply isn't one.
> 
This is certainly still being hotly debated in the C++ standards
committee.  The most recent proposal is at
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2287.pdf .  The
committee earlier approved a registration draft that proposes to add it.

Hans



More information about the Gc mailing list