"static" object in a function

Possible duplicate:
does gcc automatically initialize static variables to zero?

Are statically declared objects inside a function guaranteed initialization with 0?

For instance:

int func(void)
{
   static int x;
   ...
}

The standard promises that the x = 0first call func()?

+5
source share
5 answers

C99 Standard says:

5.1.2 runtime

... All objects in the static storage must be initialized (set to their initial values) before the program starts.

, , static , " " 0 .

+5

, .

, .bss , , main.

+1

. , :

gcc ?

+1

Yes, it is initialized to zero. But, however, it would be nice to use static method variables in general. C # clearly avoided confusion and refused to support static method variables.

http://blogs.msdn.com/b/csharpfaq/archive/2004/05/11/why-doesn-tc-support-static-method-variables.aspx

0
source

All static variables are stored in the Datasection in the memory section, where all variables are set to default values.

0
source

All Articles