www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2002/03/16/17:00:05

X-Authentication-Warning: delorie.com: mailnull set sender to djgpp-bounces using -f
From: "Guido S." <sassi AT uni DOT de>
Newsgroups: comp.os.msdos.djgpp
Subject: GCC 3.0.4 singleton/factory pattern
Date: Sat, 16 Mar 2002 22:50:44 +0100
Organization: Universitaet Hannover
Lines: 69
Message-ID: <a70elf$1sj$1@newsserver.rrzn.uni-hannover.de>
NNTP-Posting-Host: steelrose.sedan.uni-osnabrueck.de
Mime-Version: 1.0
X-Trace: newsserver.rrzn.uni-hannover.de 1016315375 1939 131.173.58.129 (16 Mar 2002 21:49:35 GMT)
X-Complaints-To: abuse AT newsserver DOT rrzn DOT uni-hannover DOT de
NNTP-Posting-Date: 16 Mar 2002 21:49:35 GMT
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2600.0000
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Hi,

It seems that the handling of static/global objects has changed from
3.0.3 to 3.0.4

I am using a singleton pattern, where I have multiple classes inherited
from a a common baseclass, each having a static 'Base *Create()' member
function.

at global level in each translation unit I then create a dummy object
which registers the childclass' Create() function in a factory database.

so basically i have a factory

class F
{
    RegisterCreate( funcptr, string )
    map< funcptr, string >
}

class Base
{
    static Base *Create():
}

---------
and in another file:

class Registrator {
    Registrator() { F::RegisterCreate( ThisChild::Create, "dummy" ) };
}

namespace {
    Registrator reg;
}

class ThisChild
{
    static Base * Create();
}


actually I using templates to do the registartor classes. but i left
them out to lessen comlexity.

so actually Registrator() should be called for each translation unit
which registers Create functions. This was true for 3.0.3 but with 3.0.4
it just doesn't get called, no matter if I declare the registrator
object in an unnamed namespace, as a static object or just plain gloabal
(there are no nameclashes by the way)

but if I register a command in the translation of main() it _gets_
called.

If I interpret the ISO standard right, the way 3.0.3 did it was the
correct one, and 3.0.4 ignores the standard on this topic.

I am just asking on this list, to confirm my suspicions before i ask on
the GCC list, and perhaps get the chance to get a workaround for this
problem until it gets fixed sometime.

I know that this looks complicated, but I did my best to cut it down to
the essential parts :)

Thanks in advance

Guido S.


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019