[Scummvm-devel] Use of global constructors

Max Horn max at quendi.de
Mon Apr 19 12:46:49 CEST 2010


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/20100419/805c1361/attachment.txt>


More information about the Scummvm-devel mailing list