Jump to content
  • Advertisement
Sign in to follow this  
dcosborn

[C] Coercion and const arrays

This topic is 4738 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
Advertisement
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  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!