Right syntax in C to define an array of 3D pointers
in a C program I need to define
float (*d_i)[3];
but later I realized that I need to define NMAX variables of this type. I tried wit开发者_如何学运维h
float (*d_i)[3][NMAX];
but it does not work.
what would be the right syntax?
Thanks
Don't guess. Just use a typedef
.
typedef float (*someType)[3];
someType d_i[NMAX];
(In case you really don't want the typedef
,
float (*d_i[NMAX])[3];
)
typedef float array_of_3_floats[3];
array_of_3_floats *d_i; /* what you have now */
array_of_3_floats d_ii[NMAX]; /* what I think you want */
array_of_3_floats (*d_iii)[NMAX]; /* maybe what you want */
Is NMAX a constant? If not, the memory allocation should be done dynamically using malloc (or equivalent).
精彩评论