RE: Question about static class objects

From: Jean-Francois Bastien <jfbastien_at_cae.com>
Date: Thu, 29 May 2008 10:42:12 -0400


> Uhm, in my mind, a static member of a class (or, as it's
> called in Java
> - a class variable) is far better style than a static variable in a
> function. Could you explain why you believe a static
> function variable
> is better style than a class variable?

Static function variables are initialized on first use, whereas static class variables are initialized at the same time as the globals. The initialization order of globals is undefined and can change when you recompile. The only thing that you're certain of is that built-in globals are initialized before complex globals. This means that if a global or another static class variable tries to use another global you can fall in undefined behavior land.

I'm not talking about thread safety here, that's an entirely different issue.

JF Received on Thu May 29 2008 - 16:43:23 CEST

This archive was generated by hypermail 2.2.0 : Thu May 29 2008 - 17:50:01 CEST