Path: utzoo!utgpu!water!watmath!clyde!cbosgd!ihnp4!ptsfa!ames!nrl-cmf!ukma!gatech!udel!rochester!rutgers!im4u!ut-sally!utah-cs!utah-gr!uplherc!esunix!rushfort From: rushfort@esunix.UUCP (Kevin Rushforth) Newsgroups: comp.lang.c Subject: Re: Limit to array size under cc? Message-ID: <594X@esunix.UUCP> Date: 21 Jan 88 00:00:00 GMT References: <3537@ames.arpa> Organization: Evans & Sutherland, Salt Lake City, Utah Lines: 39 in article <3537@ames.arpa>, lamaster@pioneer.arpa (Hugh LaMaster) says: > Is there a limit to the maximum size of an array using cc? For > some reason, the maximum number that NR can be on a Sun (3.2) is > 128766. On a VAX (Ultrix 2.0) it is 130222. Am I doing something > wrong or is it the compiler? [relevant part of example follows] > #define NR 128767 > main() > { > int red[NR]; > } This is not a limit on the size of an array imposed by your compiler, but rather a limit on the stack size imposed by your OS. 4.2/4.3 based Unix systems (as well as others) have compiled in limits on stack size (the csh command "limit" will tell you how much). To avoid the problem, declare your array statically or malloc() space for it: main() { static int red[NR]; } -or- main() { int *red; red = (int *) malloc(NR * sizeof(int)); } -- Kevin C. Rushforth Evans & Sutherland Computer Corporation UUCP Address: {ihnp4,ucbvax,decvax,allegra}!decwrl!esunix!rushfort Alternate: {bellcore,cbosgd,ulysses}!utah-cs!esunix!rushfort