Message-ID: <3587625A.81EBA2E8@post.comstar.ru> Date: Wed, 17 Jun 1998 10:29:46 +0400 From: Dim Zegebart Reply-To: zager AT post DOT comstar DOT ru Organization: Comstar Ltd. MIME-Version: 1.0 To: e96pd AT efd DOT lth DOT se CC: djgpp AT delorie DOT com Subject: Re: Help! Why is my program crashing? References: <35867E83 DOT E01 AT efd DOT lth DOT se> Content-Type: text/plain; charset=koi8-r Content-Transfer-Encoding: 7bit Precedence: bulk Peter Danielsson wrote: > Why does my program crash all the time. It's a simple program, only a > few lines: > > int WIDTH=513; > int *mapheight; > > void initmapheight(int *n)//allocateing memory > { > n=(int*)calloc((long)513*513,sizeof(int)); > if(n==NULL) > exit(-1); > } > void reset(int *m,int W2)//set to zero. Here it crashes > { > for(int a5=0;a5 for(int q=0;q m[(long)a5*W2+q]=0; > } > void main(int argc, char *argv[]) > { > initmapheight(mapheight); > reset(mapheight,100); > } To avoid problems with passing pointer to function just change your code as folows : int * initmapheight() { int *map; map=(int*)calloc((long)513*513,sizeof(int)); return(map); } int main(int argc, char *argv[]) { mapheight=inimapheight(): if (!mapheight) exit(-1); } -- ____ ____ | \ / Dim Zegebart ____/____ Moscow Russia WWW - http://www.geocities.com/siliconvalley/pines/7817 DZcomm - comm library for Allegro Palantir - multitasking kernel for Allegro (based on PDMLWP)