On Tue, Oct 22, 2013 at 10:23 AM, Steven D'Aprano <
steve+comp.lang.pyt...@pearwood.info> wrote:

> On Tue, 22 Oct 2013 16:53:07 +0000, Frank Miles wrote:
>
> [snip C code]
> > What you're missing is that arr[] is an automatic variable.  Put a
> > "static" in front of it, or move it outside the function (to become
> > global) and you'll see the difference.
>
> Ah, that makes sense. Thanks to everyone who corrected my
> misunderstanding.
>
> Well, actually, no it doesn't. I wonder why C specifies such behaviour?
> Why would you want non-global arrays to be filled with garbage?
>
>
Its a performance benefit, for cases where you are going to fill the array
from other means, such as from a file or other sources such as literals.
The global and static variables are effectively free to zero due to
standard OS behaviours.

The issue is actually more general than arrays, as the same behavior exists
for all the types in C. Stack and heap variables have undefined value when
initialized, while global and static variables (which are really the same
thing, but with differing lexical scopes) are zero-filled.


>
> --
> Steven
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to