Question on large arrays in C
bob at cald80.UUCP
bob at cald80.UUCP
Fri Feb 13 15:10:30 AEST 1987
In article <1051 at uwmacc.UUCP> jwp at uwmacc.UUCP (Jeffrey W Percival) writes:
:I am running 4.3BSD on a MicroVax II.
:I have a simple program:
:
:----------
:#include <stdio.h>
:#define N 20480
:main()
:{
: double x[N];
: double y_1[N];
: double y_2[N];
: double y_3[N];
: double y_4[N];
: char *l = "";
:
: fprintf(stdout, "hi\n");
: exit(0);
:}
:----------
:
:When I run it, I get "Segmentation violation".
:dbx reports the violation to occur on the "char *l" line.
:If I move the 5 array declarations up above main(),
:under the define statement, the program works OK.
:What is wrong with the program as listed above?
:--
My compiler (Ancient V7 68000 UNIX) won't even let me do that.
I don't think that aggregate assignments inside a block are not allowed
on most systems that I hack on. Also remember that local variables
hang out on the stack. Your compiler may not catch a stack overrun
(409600 Kbytes may be a bit much even for a VAX).
I generally stuff large arrays out in global area anyway.
That keeps you from having to pass them all the time. No flames, I
know that globals are generally to be avoided unless really necessary
but I prefer to stuff big stuff out there in case I get stuck on
another machine with small stack (8086 and company). On those
machines, 64K is all you're allowed in one data segment.
Also, the local FORTrashers find globals easier to deal with
when trying to figger out what I did (seems that they associate them
with unnamed commons or some such).
I might be completely off base on this (I don't really dig
into VAXEN much and am not sure of the architecture there) but I think
that this may be right.
--
Bob Meyer
Calspan ATC
seismo!kitty!sunybcs!cald80!bob
decvax!sunybcs!cald80!bob
More information about the Comp.lang.c
mailing list