[Scummvm-devel] Use of global constructors

Max Horn max at quendi.de
Wed May 12 10:40:31 CEST 2010


Hi folks,

since my first post on this subject, some improvements have been done, and we rely on a lot fewer global constructors now. The remaining offenders are (details in the attachment):

* Cine
* Cruise
* Parallaction
* M4
* Tinsel
* SDL backend

Cine and Cruise have the highest number of problems by far, which is not so surprising; a lot of that would probably just go away by itself if they were further OOPified.


Cheers,
Max

Am 19.04.2010 um 12:46 schrieb Max Horn:

> Hi folks,
> 
> recently I discoved the GCC option -Wglobal-constructors (in GCC 4.2.1, and probably many other versions). This is useful because it tells you about places that rely on global variables with a non-trivial constructor -- something that caused us portability issues in the past, on the PalmOS and WinCE ports and others. The problem here is that it's not always guaranteed that these constructors are really run on various ports, and this lead to all kinds of nasty workaround for things like that.
> 
> 
> I think we should try to get rid of as many of these as possible. The usual fixes are:
> 
> * change global variable to a class member
> * change global variable from a struct with a constructor to a "simple" type (POD, plain old data, in particular no constructors and no overloaded assignment operator)
> * change global variable to a pointer to the actual stuff, and init / deinit it from a suitable place. E.g. change
>  Common::List<int> g_myList;
> to
>  Common::List<int> *g_myList;
> and then add somewhere
>  g_myList = new Common::List<int>();
> 
> 
> 
> Cheers,
> Max
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: global-constructors.txt
URL: <http://lists.scummvm.org/pipermail/scummvm-devel/attachments/20100512/f22d62cd/attachment.txt>


More information about the Scummvm-devel mailing list