12.2.2.2 Static Variables
All static
variables have permanent storage duration,
even those defined inside a function which are “local static” variables. Local
static
variables only have scope in the function or block in which
they are defined, but unlike auto
variables, their memory is reserved
for the entire duration of the program. Thus they are allocated memory like other
non-auto
variables. Static variables may be accessed by other
functions via pointers since they have permanent duration.
Variables which are static
are guaranteed to retain
their value between calls to a function, unless explicitly modified via a pointer.
Variables which are static
and which are initialized
only have their initial value assigned once during the program’s execution. Thus, they
may be preferable over initialized auto
objects which are assigned a
value every time the block in which they are defined begins execution. Any initialized
static variables are initialized in the same way as other non-auto
initialized objects by the runtime startup code (see the Startup and Initialization section).