Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'static': 0.04; 'subject:Python': 0.06; '#include': 0.09; '22,': 0.09; 'arrays': 0.09; 'global,': 0.09; 'here?': 0.09; 'i++)': 0.09; 'main()': 0.09; 'reference:': 0.09; '>>': 0.16; 'array.': 0.16; 'garbage': 0.16; 'trusty': 0.16; 'skip:# 20': 0.16; 'wrote:': 0.18; 'variable': 0.18; '<': 0.19; 'to:name:python- list@python.org': 0.22; 'this?': 0.23; "aren't": 0.24; 'received:209.85.214.174': 0.24; '>': 0.26; 'references': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'array': 0.29; 'message-id:@mail.gmail.com': 0.30; 'url:mailman': 0.30; "d'aprano": 0.31; 'gcc': 0.31; 'steven': 0.31; 'subject:end': 0.31; 'url:python': 0.33; 'skip:_ 10': 0.34; 'received:209.85': 0.35; 'no,': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'c++': 0.36; 'url:listinfo': 0.36; 'url:org': 0.36; 'received:209': 0.37; 'auto': 0.38; 'filled': 0.38; 'to:addr :python-list': 0.38; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'url:mail': 0.40; 'skip:u 10': 0.60; 'hang': 0.67; 'believe': 0.68; 'edwards': 0.91; '8bit%:18': 0.93; '2013': 0.98 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:content-type; bh=D4Rdvd17+2S0YecUl+R2k4pXXsSJmslZAFuBTDhOwJ4=; b=aIpR8cGqxwepHHOU/k8dKx+5DR286IRzFRTZcPLBSRad7qmDud7eD/1/auxYLXQRHZ 7BTQJUNDhsNukNkoLut0MU3zD4Nr1VhfqdzOw2e1twiQ25TWAfBUhuhDr8lOEzMGy6n1 hCOvDHWqcO8QLYBrcuB0CfNo1P4R3poxT6m+c8ivofzSZrAKMKX/TczsrdIvPlZk5fnk avJt1In1/6O7oqBZBeLRGV6otCVmk8VrT0wWafkB3qxegnFVBmBuV01j2MSHD1HTyO2e iimvWv8Srk8VPxC7LZvsp6mT2sklhk/lEYNi7cFYGYfglcxhba+Y5ItBvi0NtOR/jUkJ 8P1A== X-Gm-Message-State: ALoCoQlk/c7km28izPUU5ci8yHOL8rHSyLh/L4BxYFTCI1ImSPvpwwDMlc++hOZIDX3ntQVu79vj X-Received: by 10.182.81.65 with SMTP id y1mr392415obx.89.1382460750026; Tue, 22 Oct 2013 09:52:30 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <5266aa80$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> From: Chris Kaynor Date: Tue, 22 Oct 2013 09:52:09 -0700 Subject: Re: Python Front-end to GCC To: "python-list@python.org" Content-Type: multipart/alternative; boundary=047d7b2e4d32ebec1404e95739f0 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: 197 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1382460759 news.xs4all.nl 15977 [2001:888:2000:d::a6]:33721 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:57274 --047d7b2e4d32ebec1404e95739f0 Content-Type: text/plain; charset=ISO-8859-1 On Tue, Oct 22, 2013 at 9:40 AM, Steven D'Aprano < steve+comp.lang.python@pearwood.info> wrote: > On Tue, 22 Oct 2013 15:39:42 +0000, Grant Edwards wrote: > > >> No, I was thinking of an array. Arrays aren't automatically initialised > >> in C. > > > > If they are static or global, then _yes_they_are_. They are zeroed. > > Not that I don't believe you, but do you have a reference for this? > Because I keep finding references to uninitialised C arrays filled with > garbage if you don't initialise them. > > Wait... hang on a second... > > /fires up the ol' trusty gcc > > > [steve@ando c]$ cat array_init.c > #include > > int main() > { > int i; > int arr[10]; > for (i = 0; i < 10; i++) { > printf("arr[%d] = %d\n", i, arr[i]); > } > printf("\n"); > return 0; > } > > [steve@ando c]$ gcc array_init.c > [steve@ando c]$ ./a.out > arr[0] = -1082002360 > arr[1] = 134513317 > arr[2] = 2527220 > arr[3] = 2519564 > arr[4] = -1082002312 > arr[5] = 134513753 > arr[6] = 1294213 > arr[7] = -1082002164 > arr[8] = -1082002312 > arr[9] = 2527220 > > What am I missing here? > The array you made there is an auto variable (stack), not a static or a global. Try one of the following (neither has been tested): Static: int main() { int i; static int arr[10]; for (i = 0; i < 10; i++) { printf("arr[%d] = %d\n", i, arr[i]); } printf("\n"); return 0; } Global: int arr[10]; int main() { int i; for (i = 0; i < 10; i++) { printf("arr[%d] = %d\n", i, arr[i]); } printf("\n"); return 0; } As for a reference: http://stackoverflow.com/questions/1831290/static-variable-initialization and http://stackoverflow.com/questions/3373108/why-are-static-variables-auto-initialized-to-zero, both of which then reference the C++ standard. > > -- > Steven > -- > https://mail.python.org/mailman/listinfo/python-list > --047d7b2e4d32ebec1404e95739f0 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
On Tue, Oct 22, 2013 at 9:40 AM, Steven D'Aprano <steve+comp.lang.python@pearwood.info> wrote:<= br>
On Tue, 22 Oc= t 2013 15:39:42 +0000, Grant Edwards wrote:

>> No, I was thinking of an array. Arrays aren't automatically in= itialised
>> in C.
>
> If they are static or global, then _yes_they_are_. =A0They are zeroed.=

Not that I don't believe you, but do you have a reference for thi= s?
Because I keep finding references to uninitialised C arrays filled with
garbage if you don't initialise them.

Wait... hang on a second...

/fires up the ol' trusty gcc


[steve@ando c]$ cat array_init.c
#include<stdio.h>

int main()
{
=A0 int i;
=A0 int arr[10];
=A0 for (i =3D 0; i < 10; i++) {
=A0 =A0 printf("arr[%d] =3D %d\n", i, arr[i]);
=A0 =A0 }
=A0 =A0 printf("\n");
=A0 =A0 return 0;
}

[steve@ando c]$ gcc array_init.c
[steve@ando c]$ ./a.out
arr[0] =3D -1082002360
arr[1] =3D 134513317
arr[2] =3D 2527220
arr[3] =3D 2519564
arr[4] =3D -1082002312
arr[5] =3D 134513753
arr[6] =3D 1294213
arr[7] =3D -1082002164
arr[8] =3D -1082002312
arr[9] =3D 2527220=A0

What am I missing here?

The array you m= ade there is an auto variable (stack), not a static or a global. Try one of= the following (neither has been tested):

Static:<= /div>

int main()
{
=A0 int i;
=A0 static int arr[10]= ;
=A0 for (i =3D 0; i < 10; i++) {
=A0 =A0 printf("arr[%d] = =3D %d\n", i, arr[i]);
=A0 =A0 }
=A0 =A0 printf("\n");=
=A0 =A0 return 0;
}



Global:

int arr[10];
int main()
{
=A0 i= nt i;
=A0 for (i =3D 0; i < 10; i++) {
=A0 =A0 printf("arr[%d= ] =3D %d\n", i, arr[i]);
=A0 =A0 }
=A0 =A0 printf("\n");
=A0 =A0 return 0;
}


--047d7b2e4d32ebec1404e95739f0--