Sign in to follow this  

[C] Coercion and const arrays

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this