My C arrays are too large

Eliot Moss moss@cs.umass.edu
Fri Sep 13 12:37:00 GMT 2019


On 9/13/2019 8:10 AM, Blair, Charles E III wrote:
> My apologies for failing to reply on-list.  I don't know how :(
> 
> My machine is 64 bit, and I hope I installed the correct version of cygwin.
> 
> This program:
> 
> #include<stdio.h>
> int main(){char *a[50][8192];
> return 0;}
> 
> compiles with gcc  (no special options) but gives "Segmentation fault".

Ah, it's a local variable, which means it's going on your stack.
Have you set a stack size limit that's large enough?  On my system
ulimit -a will report all the limits, and ulimit -s can be used to
set the stack limit.

In my 64-bit cygwin, ulimit -a reports a stack size of 2032 K bytes.
Your structure will be 50 * 8K * 8 = 3200 K bytes.  So if your setup
is similar to mine, your tack isn't big enough.  If you declared the
array outside of main so that it is global and in the bss area, if
would probably work out of the box, but adjusting your stack size
should fix your problem, I believe.

Regards - EM

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple



More information about the Cygwin mailing list