Messages in this thread | | | Date | Sat, 5 Jul 1997 22:21:49 -0400 (EDT) | From | genie <> | Subject | why doesn't the following cause a coredump in Linux? |
| |
The following program will not cause a coredump even though it looks like I am assigning a value to a illegal memory reference. Why is this? Am I allocating more memory than I need in my dim2d or am I allocating it the wrong way? I am not sure why the main() references won't cause a core dump, since it looks like I'm poking past the array's boundaries (at least in the static case, one would think so). Can someone give me a hint on memory allocation and the layout of a statis/dynamic array in memory under Linux(or UNIX even, perhaps)? Thank you dearly.
M. Naskovski
-- #include <stdio.h> #include <stdlib.h>
double **dim2d(int n, int m) /* n = # of rows, m = # of columns */ { int i; double **narr; narr=(double **)calloc(n, sizeof(double *)); if (narr == NULL) return NULL; for (i=0; i < n; i++) { narr[i]=(double *)calloc(m, sizeof(double)); if (narr[i] == NULL) return NULL; } return narr; }
main() { double **a=dim2d(1,1); double a2[1][1]; a[0][0]=255; a[0][5]=256;
a2[0][0]=255; a2[0][5]=256; }
| |