1

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

3 Answers 3

2

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

)

Sign up to request clarification or add additional context in comments.

Comments

1
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 */

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.