From: Art Haas <arthur.haas@westgeo.com>
Subject: Re: 13 line c program segfaults on alpha/linux, but not intel. why?
Date: 29 Jun 2001 15:59:55 -0500 [thread overview]
Message-ID: <lrlmmb57ec.fsf@haasart1.dhcp.wg.waii.com> (raw)
In-Reply-To: 9hidff$6la@taumsauk.cs.wustl.edu
berkley@taumsauk.cs.wustl.edu (Berkley Shands) writes:
> you have overrun the static storage limit for arrays...
>
> #include <stdio.h>
#include <stdlib.h>
> #define SIZE 1047977
>
> main ()
> {
> /* double vector_x [SIZE]; */
> double *vector_x = NULL;
> int x = 0;
>
> vector_x = (double *) malloc(sizeof(double) * (SIZE + 1));
vector_x = 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
> [ ... snip ... ]
You need to `#include <stdlib.h>' for the prototype for malloc(), and
you don't need the cast. I think the changes above should rid you of
the warnings generated by the compiler, too.
--
###############################
# Art Haas
# (713) 689-2417
###############################
next prev parent reply other threads:[~2001-06-29 20:59 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-06-29 16:10 13 line c program segfaults on alpha/linux, but not intel. why? Patrick Paul
2001-06-29 16:51 ` Robert M. Riches Jr.
2001-06-29 17:21 ` Berkley Shands
2001-06-29 20:59 ` Art Haas [this message]
2001-06-29 17:36 ` Serguei Patchkovskii
2001-06-29 17:59 ` Terrance Richard Boyes
2001-06-29 19:25 ` Patrick Paul
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox