RE: Static memory allocation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Ankit wrote:

>[ankit@Ankit fft]$ cat try2.c
>#include <stdio.h>
>int main()
>{
>  double a[1450][1450];
>  a[1450][0]=999.999;
>  printf("%lf\n",a[1450][0]);
>  return 0;
>}
>[ankit@Ankit fft]$ gcc try2.c
>[ankit@Ankit fft]$ ./a.out
>Segmentation fault
>[ankit@Ankit fft]$

This is a classic `off-by-one' error.  When you allocate an
array int a[10] you are asking for ten storage locations that 
are numbered 0 -- 9. (not 10).

In your program, the legal range for each index is 0-1449 (not 1450).

George

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux