|
 |
Slime wrote:
>> More exactly, in C at least, any variables allocated statically start with
>> a default value of zero appropriate for their type. That includes static
>> variables allocated inside a function.
>
>
> I was under the impression that global variables are initialized to zero,
> but you can't trust local variables because the stack has whatever garbage
> data was left on it from previously called functions.
Correct. I was also pointing out that they get initialized to the type's
version of zero, whatever that might be. (I.e., pointers may not have
all zero bits in them; they get initialized to null instead.) Rarely can
you see this difference. :-)
And variables that are static but not global also get initialized.
--
Darren New / San Diego, CA, USA (PST)
Post a reply to this message
|
 |