for example
static char all_data;
without initializing value to it. what is the default value? Or is it a Undefined Behavior?
I tried on my gcc-4.6 the answer is 0.
Thanks.
for example
static char all_data;
without initializing value to it. what is the default value? Or is it a Undefined Behavior?
I tried on my gcc-4.6 the answer is 0.
Thanks.
Per C99:
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.
According to C standard static variables are by default initialized to zero. But it's a good practice to always initialize it explicitly. In this link there is a para named "Initialization" you will find your necessary information there.
open-std.org: ISO/IEC 9899:TC2 tells us:
if an object that has static storage duration is not initialized explicitly, then ... if it has arithmetic type, it is initialized to (positive or unsigned) zero
(page 126)
The char
type is an arithmetic type. You are guaranteed initialization to 0
.