On Sun, Jan 23, 2011 at 3:44 PM, Geoff McLane wrote:

> And I am not so sure MSVC even zeros static variables,
> unless specifically set to NULL/0, unlike as suggested
> for gcc, thus say :-
>
> static char * cp;
> void func() {
>    if (cp == NULL)
>        cp = malloc(val);
> can also be a problem...
>
>
Are you sure? Initialization of global variables is required by the C99
standard - and I think was already part of C90 (ANSI C).
Ok, few compilers are fully compliant - especially not C99, but all
compilers I know at least comply with this rule (admittedly, I know nothing
about MSVC... :)) ).

C99 says
"[...]
If an object that has static storage duration is not initialized explicitly,
then:
— if it has pointer type, it is initialized to a null pointer;
— if it has arithmetic type, it is initialized to (positive or unsigned)
zero;
— if it is an aggregate, every member is initialized (recursively) according
to these rules;
— if it is a union, the first named member is initialized (recursively)
according to these
rules."

I mainly use gcc and a number of weird compilers for embedded systems -
which all comply with this rule.
But you're right, personally I also prefer to explicitly initialize all
variables (i.e. "int foo=0;" instead of "int foo;") since it's more clear,
better style and it doesn't cause issues when a global variable needs to be
moved into a local context.
It'd still be interesting to know if MSVC really doesn't comply with the
rule above - this could certainly be a source for several MSVC-specific FG
issues (just guessing here...).

cheers,
Thorsten
------------------------------------------------------------------------------
Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
Finally, a world-class log management solution at an even better price-free!
Download using promo code Free_Logger_4_Dev2Dev. Offer expires 
February 28th, so secure your free ArcSight Logger TODAY! 
http://p.sf.net/sfu/arcsight-sfd2d
_______________________________________________
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel

Reply via email to