From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111c93,a191e211a3e9da1d X-Google-Attributes: gid111c93,public X-Google-ArrivalTime: 2001-06-29 10:21:52 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!headwall.stanford.edu!unlnews.unl.edu!newsreader.wustl.edu!taumsauk.cs.wustl.edu!not-for-mail From: berkley@taumsauk.cs.wustl.edu (Berkley Shands) Newsgroups: comp.os.linux.alpha Subject: Re: 13 line c program segfaults on alpha/linux, but not intel. why? Date: 29 Jun 2001 12:21:51 -0500 Organization: Washington University, St. Louis MO Message-ID: <9hidff$6la@taumsauk.cs.wustl.edu> References: <2M1%6.147007$Bz6.91285@sjc-read.news.verio.net> NNTP-Posting-Host: cs.wustl.edu X-Trace: newsreader.wustl.edu 993835278 15994 128.252.165.15 (29 Jun 2001 17:21:18 GMT) X-Complaints-To: usenet@newsreader.wustl.edu NNTP-Posting-Date: Fri, 29 Jun 2001 17:21:18 +0000 (UTC) Xref: archiver1.google.com comp.os.linux.alpha:3208 In article <2M1%6.147007$Bz6.91285@sjc-read.news.verio.net>, Patrick Paul wrote: >a little help from those programmer types out there. i compared >/proc/sys/kernel entries between intel and alpha machines, and that wasn't >the problem. > >what happens is that i compile this proggy > >#include >#define SIZE 1047977 > >main () >{ > double vector_x [SIZE]; > int x; > > for ( x = 0; x < SIZE; x++ ) > vector_x [x] = (double) x; > > printf ("\n x [%d] = %.4f\n\n", SIZE - 1, vector_x [SIZE - 1] ); >} > > >which compiles fine > >but when i run it on alpha, it coredumps and segfaults. > >on intel, it works fine. > >any ideas? > >tia > >-- >Patrick Paul >Microway.com >patrick@no_microway_spam.com > > you have overrun the static storage limit for arrays... #include #define SIZE 1047977 main () { /* double vector_x [SIZE]; */ double *vector_x = NULL; int x = 0; vector_x = (double *) malloc(sizeof(double) * (SIZE + 1)); if (! vector_x) { perror("malloc failed"); exit(-1); } for ( x = 0; x < SIZE; x++ ) vector_x [x] = (double) x; printf ("\n x [%d] = %.4lf\n\n", SIZE - 1, vector_x [SIZE - 1] ); } (Xp1000 512mb 500mhz ev6 redhat 7.0 running 2.4.5) Xp1000@alleycat /tmp> cc test.c test.c: In function `main': test.c:10: warning: cast to pointer from integer of different size Xp1000@alleycat /tmp> a.out x [1047976] = 1047976.0000 you fight many battles with gcc, some you win, some you don't. large static arrays will crash many systems, not just alphas. Try that one under Micro$oft :-) Your code on Tru64 V5.1a generates Stack overflow: pid 12853, proc a.out, addr 0x11f7fd2b0, pc 0x120001190 Segmentation fault Xp1000@alleycat2 /tmp> limit stack un Xp1000@alleycat2 /tmp> a.out x [1047976] = 1047976.0000 My general rule is any array over 128Kb should be malloc() or new(). Long Live Alpha! berkley -- berkley@cs.wustl.edu "Software Enforcer"