[LC++]declaring and using manipulating global variables

Carlo Wood carlo at alinoe.com
Sat May 17 18:47:02 UTC 2003


On Fri, May 16, 2003 at 09:11:04AM -0000, devraj  sanyal wrote:
> There is no harm in using globals. It improves effciency etc.

In C++ there is a lot AGAINST using global non-POD variables.
The 'global/static initialization order fiasco' being
one of them; it usually isn't threadsafe either.

The correct solution for OOPrograms are singletons,
or otherwise wrapped objects.  Basically then a pointer
(which is POD) is then used to access the global object,
but the object itself is not declared globally.

-- 
Carlo Wood <carlo at alinoe.com>

PS POD = Plain Old Data, objects that can be initialized
   without constructor.



More information about the tuxCPProgramming mailing list