Tuesday, January 6, 2009

Use singletons instead of static member vars and functions

A developer's code used macros, defines, and statics to initialize the constant variables used in the top level of the program.
This worked on Linux. However, since the ISO/ANSI C++ standard does not guarantee the initialization sequence
of the constructors there is a 50/50 chance that a compiler on a new platform will use a different init sequence resulting in
segfaults/problems. This is exactly what happened on the Mac. So I converted his macros/statics/defines to singleton
classes and things seem to be working better on the Mac. I had to change about 3k lines of code to use the singleton refs instead of defines and statics.

No comments:

Post a Comment