A pointer to a 3-D array, or an array of ptrs to 2-D arrays?

MARWK at levels.sait.edu.au MARWK at levels.sait.edu.au
Wed Nov 15 05:23:43 AEST 1989


Why does (1) work but (2) does not?

(1) p = (int (*) [13][2][64]) malloc (sizeof(int) * 13 * 2 * 64)
    
    *p[i][j][k] = 6

(2) p = (int (*) [2][64]) malloc (sizeof(int) * 13 * 2 * 64)

    p[i][j][k] = 6

These are both supposed to be ways of dynamically creating a 3-dimensional
array for accessing as such, but (1) causes a segmentation error when run
on the ENCORE.
Thanks in advance.

Ray



More information about the Comp.lang.c mailing list