Python Front-end to GCC

MRAB python at mrabarnett.plus.com
Tue Oct 22 13:42:37 EDT 2013


On 22/10/2013 18:23, Steven D'Aprano 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?
>
Static variables need be initialised only once, whereas auto variables
exist on the stack, so they would need to be initialised repeatedly,
which was considered too expensive, especially as they would be
assigned to before use anyway (hopefully!).

Of course, these days, with our much faster CPUs, we're not so
bothered, and prefer to allocate on the heap.




More information about the Python-list mailing list