<div dir="ltr"><div class="gmail_extra">On Tue, Oct 22, 2013 at 10:23 AM, Steven D'Aprano <span dir="ltr"><<a href="mailto:steve+comp.lang.python@pearwood.info" target="_blank">steve+comp.lang.python@pearwood.info</a>></span> wrote:<br>

<div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Tue, 22 Oct 2013 16:53:07 +0000, Frank Miles wrote:<br>
<br>
[snip C code]<br>
<div class="im">> What you're missing is that arr[] is an automatic variable.  Put a<br>
> "static" in front of it, or move it outside the function (to become<br>
> global) and you'll see the difference.<br>
<br>
</div>Ah, that makes sense. Thanks to everyone who corrected my<br>
misunderstanding.<br>
<br>
Well, actually, no it doesn't. I wonder why C specifies such behaviour?<br>
Why would you want non-global arrays to be filled with garbage?<br>
<div class="HOEnZb"><div class="h5"><br></div></div></blockquote><div><br></div><div>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.</div>

<div><br></div><div>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.</div>

<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">
<br>
--<br>
Steven<br>
--<br>
<a href="https://mail.python.org/mailman/listinfo/python-list" target="_blank">https://mail.python.org/mailman/listinfo/python-list</a><br>
</div></div></blockquote></div><br></div></div>