Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.028 X-Spam-Evidence: '*H*': 0.94; '*S*': 0.00; 'subject:Python': 0.06; 'arrays': 0.09; 'contexts': 0.09; 'debugging.': 0.09; 'inserted': 0.09; 'cc:addr:python-list': 0.11; 'ah,': 0.16; 'cc:name:python list': 0.16; 'garbage': 0.16; 'nan': 0.16; 'to:addr:pearwood.info': 0.16; 'to:addr:steve+comp.lang.python': 0.16; "to:name:steven d'aprano": 0.16; 'variable.': 0.16; 'zeros': 0.16; 'wrote:': 0.18; 'first.': 0.19; 'value.': 0.19; 'later': 0.20; 'memory': 0.22; 'cc:addr:python.org': 0.22; 'error': 0.23; '(such': 0.24; 'specifies': 0.24; "haven't": 0.24; 'cc:2**0': 0.24; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'quickly': 0.29; 'wonder': 0.29; 'waste': 0.30; 'message- id:@mail.gmail.com': 0.30; "d'aprano": 0.31; 'steven': 0.31; 'subject:end': 0.31; 'values.': 0.31; 'front': 0.32; 'supposed': 0.32; 'everyone': 0.33; 'but': 0.35; 'received:google.com': 0.35; 'useful': 0.36; 'thanks': 0.36; 'expected': 0.38; 'filled': 0.38; 'rather': 0.38; 'skip:u 10': 0.60; 'range': 0.61; "you're": 0.61; "you'll": 0.62; 'show': 0.63; 'kind': 0.63; 'such': 0.63; 'become': 0.64; 'more': 0.64; 'between': 0.67; 'frank': 0.68; 'results': 0.69; 'actually,': 0.84; 'difference.': 0.84; 'distinguish': 0.84; 'oscar': 0.84; 'mistake': 0.91; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=BrNz2k5QRoK7Vo7hWez5/4TBoPSJvJCgCU+zObPjREg=; b=l1XTWshVZ7vk713CB23wE+vXdEdAN2T7NgKyeMkPY0ICxSw/2Blskajn7N5mx1C85W B4bnPAMg+uj88KNr9CpboGMmzhxyz+P/PRuApVR8khAs1r3F7ZnqbChbLKz1LOTlyi+O 87HxP5qeZQUpgid7M8hPVeG3OLbg2bGP7qENsY6AzxiARpJXk98w8XeKpDGeK13xZTw/ 36Ssw041WX+nLrcBmGLl730jP0fcP5RJyTH/JyHeRRO3MM5O2Jc9lzBlwjkyCCh2rQjN alAJU/Mmu7hyVneB94pwmjxZLJ6K/AiWuaKiQRlaj25G+WW2bcuLtxgeP9y71XZQv4x5 K7NA== X-Received: by 10.220.98.212 with SMTP id r20mr86295vcn.48.1382463494899; Tue, 22 Oct 2013 10:38:14 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <5266b496$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <4012031f-5334-4be8-a673-e0d8c8917fb2@googlegroups.com> <5264dbbe$0$30000$c3e8da3$5496439d@news.astraweb.com> <5265bba8$0$29981$c3e8da3$5496439d@news.astraweb.com> <526668e5$0$29981$c3e8da3$5496439d@news.astraweb.com> <52669852$0$29981$c3e8da3$5496439d@news.astraweb.com> <5266aa80$0$29981$c3e8da3$5496439d@news.astraweb.com> <5266b496$0$29981$c3e8da3$5496439d@news.astraweb.com> From: Oscar Benjamin Date: Tue, 22 Oct 2013 18:37:54 +0100 Subject: Re: Python Front-end to GCC To: "Steven D'Aprano" Content-Type: text/plain; charset=ISO-8859-1 Cc: Python List X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 33 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1382463497 news.xs4all.nl 15884 [2001:888:2000:d::a6]:37797 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:57283 On 22 October 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? It's not that you want them filled with garbage but rather that you know you will fill them with useful values later and you don't want to waste time pre-filling them with zeros first. Or perhaps you have some other way of knowing which values are to be considered initialised. This is reasonable in some contexts. OTOH why in particular would you want to initialise them with zeros? I often initialise arrays to nan which is useful for debugging. It means that you can see if you made a mistake when you were supposed to have initialised everything to useful values. In many contexts it would be difficult to distinguish between a valid zero and a zero because you haven't yet inserted a value. This kind of error can show up more quickly if you don't zero the memory since the uninitialised values will often be out of range for what you expected and will give very noticeable results (such as a seg-fault). Oscar