Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!mnetor!uunet!seismo!sundc!rlgvax!vrdxhq!umd5!mimsy!chris
From: chris@mimsy.UUCP (Chris Torek)
Newsgroups: comp.lang.c
Subject: Re: Limit to array size under cc?
Message-ID: <9583@mimsy.UUCP>
Date: Tue, 1-Dec-87 04:38:22 EST
Article-I.D.: mimsy.9583
Posted: Tue Dec  1 04:38:22 1987
Date-Received: Fri, 4-Dec-87 04:06:47 EST
References: <3537@ames.arpa>
Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742
Lines: 44

In article <3537@ames.arpa> lamaster@pioneer.arpa (Hugh LaMaster) asks:
>Is there a limit to the maximum size of an array using cc?

and notes that the following program (my condensed version) crashes:

	#define NR 128767

	main() { int red[NR]; red[0] = 0; }

Time for the semi-annual stack size discussion again, I see....

Assuming that your compiler implements local arrays by using a
stack, there are several reasons for size limitations:

0) The compiler may use a register offset addressing mode with
   a fixed maximum offset.  Old Sun 68000 compilers, for instance,
   used a6@(offset), which limits the maximum offset to -32768,
   or 8192 four-byte integers.

1) There may be a total stack size limit imposed by the operating
   system and/or machine architecure.  `Large model' compilers for
   the 80x86 family tend to use a single stack segment, limiting
   one to 65536 bytes of stack.

2) [the one that bit you]  The 4BSD kernels (upon which the Ultrix
   kernels are based), like many other paging systems, want to be
   able to tell a `good' stack reference fault, where a program is
   growing its stack in a properly controlled manner, from a `bad'
   fault, where the program has managed to put junk into its stack
   pointer, or something equally incorrect.  To this end it has
   a `stacksize' resource limit.  In 4.3BSD, the default value for
   this limit is 512 kB.  The program above uses very nearly 512k
   for the array `red' alone; the space required for the rest of
   the program makes running that program exceed this.

   Solution: use the C-shell built in `limit' command, e.g.,
   `limit stacksize 1m' (yes, megabytes should be M, but csh
   refuses to believe in millibytes :-) so you may use lowercase).
   The built-in `unlimit' command raises a limit to its maximum
   value.  Alternatively, the program itself can set its stacksize
   limit.  For details, see man 1 csh and man 2 setrlimit.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7690)
Domain:	chris@mimsy.umd.edu	Path:	uunet!mimsy!chris