Mail Archives: djgpp/1996/04/23/12:21:55
Xref: | news2.mv.net comp.os.msdos.djgpp:3010
|
From: | Marcelo Cantos <mcantos AT ocean DOT com DOT au>
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Re: How safe is this?
|
Date: | Mon, 22 Apr 1996 22:43:12 +1100
|
Organization: | (private)
|
Lines: | 27
|
Message-ID: | <317B70D0.7585@ocean.com.au>
|
References: | <4laoi6$cgk AT groa DOT uct DOT ac DOT za>
|
NNTP-Posting-Host: | 203.12.234.172
|
Mime-Version: | 1.0
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Fabian Nunez wrote:
> class __autorun__
> {
> public:
> __autorun__(void) { start(); };
> } __autorun__;
> My question is - how save and/or portable is this?
This is a quite conventional way of initializing data and is perfectly safe and portable.
One caveat is that there is no standard which determines the order of initialization of
global objects. Hence, if, for example, your constructor calls another library that itself
is initialized by a global object constructor, you have no portable way of guaranteeing
that the library's constructor will be called before yours. One possible solution to this
problem is if the library's constructor calls, say, an init() function, which can be called
any number of times, then your global constructor could call init() before using the
library. eg:
...
__autorun__(void) { init_other_library(); start(); }
...
start() { call_other_library(); }
...
Incidentally, the void argument is a C relic which really doesn't belong in a class member
function; just use __autorun__(). Mind you, this is merely my opinion; I don't know where
the "style masters" stand on this issue.
- Raw text -