Sign in to follow this  

[C] Coercion and const arrays

This topic is 4487 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to pass a non-const array to a function that takes a const array. Now I assumed that C would implicitly perform the const conversion. Instead its giving me warnings about passing an incompatible pointer type. I'm guessing that C doesn't coerce const arrays like it does with other types. Am I right? Some additional information if you need it:
typedef float mat3_t[3][3];
// function mat3_cat - concatenates two matrices
// m0 is the output matrix, needed because C can't return arrays
// m1 and m2 are the matrices to be concatenated
void mat3_cat(mat3_t m0, const mat3_t m1, const mat3_t m2);

mat3_t m0, m1, m2;
mat3_cat(m0, m1, m2); // m1 and m2 are non-const; "incompatible pointer type"

Share this post


Link to post
Share on other sites
Awesome, thanks. Now to figure out what this means and pray that I don't have to rewrite too much code...

Share this post


Link to post
Share on other sites
Nah, the only thing you'll have to rewrite will be your argument list (plus, probably, adding a typedef const float * const * const_mat3_t).

Share this post


Link to post
Share on other sites
Sign in to follow this