tags:

views:

31

answers:

3

Hi,

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 with

   float (*d_i)[3][NMAX];

but it does not work.

what would be the right syntax?

Thanks

+2  A: 

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];

)

KennyTM
A: 

Is NMAX a constant? If not, the memory allocation should be done dynamically using malloc (or equivalent).

Dasvid
+1  A: 
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 */
pmg