Results 1 to 4 of 4
Size of array in case of multiple declaration of array of higher size in C
--------------------------------------------------------------------------------
As per your suggestion the following program work
#include <stdio.h>
float x[9500][9500];
int main(void)
...
- 12-19-2007 #1Just Joined!
- Join Date
- Dec 2007
- Location
- Meerut, Up, India
- Posts
- 6
Error message killed in yje compilation of C Program
Size of array in case of multiple declaration of array of higher size in C
--------------------------------------------------------------------------------
As per your suggestion the following program work
#include <stdio.h>
float x[9500][9500];
int main(void)
{
printf("fred\n");
x[9499][9499]=3.0/5.0;
printf("%f\n",x[9499][9499]);
return 0;
}
But when we declare more than one two-dimensional array then the error" KILLED" is flashed in the following prgram. Please try to help so that i could declare more than one two dimensional array of float type as it is required in our research program.
#include <stdio.h>
float x[9500][9500];
float y[9500][9500];
int main(void)
{
printf("fred\n");
x[9499][9499]=3.0/5.0;
printf("%f\n",x[9499][9499]);
y[9499][9499]=3.0/5.0;
printf("%f\n",y[9499][9499]);
return 0;
}
output message-"killed"
- 12-19-2007 #2
- 12-19-2007 #3
Seems to work for me. Output:
The problem might not be with the program but with the system you are trying to run it on. I'm not sure what the problem might be.Code:fred 0.600000 0.600000
My guess is that when creating that big array the program allocates memory from the stack. There is probably a limit on your system somewhere that limits the amount of memory that can be allocated.
Edit:
You could test:
The first command will display the current limit and the second is used to set the limit. I don't know how much memory you'll need. I'm currently at my school so I can't test it. On the computer I successfully ran the program on the limits are:Code:$ ulimit -a $ ulimit -s 1024
> wje_lf: haha! Have you ever noticed that the "t" and "h" keys are very close to "y" and "j" ? It took me a while to figure that one out.Code:time(seconds) unlimited file(blocks) unlimited data(kbytes) unlimited stack(kbytes) 8192 coredump(blocks) 0 nofiles(descriptors) 256 vmemory(kbytes) unlimited
- 12-19-2007 #4Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Hi.
I agree with nalg0rath. If we are correct, then using ulimit, and perhaps a few experiments might reveal the maximum sizes of data arrays you can use. A parameterized version of your source file:
On my system, one error message that I get from gcc for the SIZE 40000 on a box that has 1 GB of memory, gcc (GCC) 3.3.5 (Debian 1:3.3.5-Code:#include <stdio.h> #define SIZE 40000 #define SM (SIZE-1) float x[ SIZE ][ SIZE ]; float y[ SIZE ][ SIZE ]; int main( void ) { int mysize = SM; printf( "fred running with size %d \n", mysize ); x[ mysize ][ mysize ] = 3.0 / 5.0; printf( "%f\n", x[ mysize ][ mysize ] ); y[ mysize ][ mysize ] = 3.0 / 5.0; printf( "%f\n", y[ mysize ][ mysize ] ); return 0; }
is:
For size 20000, I was able to compile without error, but for execution I got:Code:c1.c:5: error: size of array `x' is too large
Note that this was during execution, not compilation as your thread title is written.Code:% ./c1 Killed
You can change the definition of SIZE to see what might fit in the computer in question.
For many questions like this, it is helpful to include something about your environment -- which OS and compiler you are using, the memory and CPU on your computer, etc. ... cheers, drlWelcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )


Reply With Quote