Re: Bug#116823: Debian's g++-3.0 forgets to generate some code.
On Wed, Oct 24, 2001 at 11:48:02PM +0200, Martin v. Loewis wrote:
> > Lots of real C++ code is order-sensitive. This is a serious problem and
> > there are a couple of ugly solutions to it.
>
> I'd say that the best solution would be to get rid of globals. This is
> actually very easy:
>
> If you have
> TYPE VAR = INITIALIZER;
> replace that with
> TYPE& getVAR(){ static TYPE obj = INITIALIZER; return obj; }
>
> Then use getVAR() whereever you've used VAR before. For backwards
> compatibility, you can even do
>
> #define VAR (getVAR())
>
> In understand that modules don't share global objects (perhaps except
> for the module singleton), so removing global should be a local change
> inside each module only.
Beware, use of nontrivial static local initialization is inherently
thread-unsafe without direct compiler support.
Nathan Myers
ncm at cantrip dot org
Reply to: