Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Const correctness: add const qualifiers for unmodified function parameters #281

Closed
CaspianA1 opened this issue Mar 10, 2023 · 4 comments
Closed

Comments

@CaspianA1
Copy link

The functions I've seen in this library do not label unmodified parameters with const qualifiers. This causes some problems with a lot of existing code in a project that I'm working on.

Say that I'm doing this:

const vec3 a = {1, 2, 3}, b = {1, 1, 2};

vec3 sum;
glm_vec3_add(a, b, sum);

With enough Clang warnings flags, Clang starts to complain:

warning: passing 'const vec3' (aka 'const float[3]') to parameter of type 'float *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]

In order to fix this, I must do an ugly const-cast in order to remove the error:

glm_vec3_add((float*) a, (float*) b, sum);

Therefore, I suggest adding const qualifiers to the unmodified parameters of each function signature. In this case, this would change the signature of glm_vec3_add from void glm_vec3_add(vec3 a, vec3 b, vec3 dest) to void glm_vec3_add(const vec3 a, const vec3 b, vec3 dest).

This would not be too hard to add, or break any existing code, it would just take a little while to update each function signature. For the sake of const-correctness, please consider making this change!

@recp
Copy link
Owner

recp commented Mar 10, 2023

Hi @CaspianA1,

This is discussed somehow earlier at: #83 also see #86. If there is a good way to do this we can approach to. Any feedbacks discussions are welcome

@Kharzette
Copy link

I've constified my fork, and all seems well with what I use. I haven't changed the comments though.

@Kharzette
Copy link

Hmm nevermind, looks like I have some errors to fix that don't get built locally. (WebAssembly whatever that is)

@recp
Copy link
Owner

recp commented Mar 1, 2024

@Kharzette thanks,

There are some issues discussed at: #83 like:

warning: pointers to arrays with different qualifiers are incompatible in ISO C [-Wpedantic]

Let's merge this issue with that one by closing this.

@recp recp closed this as completed Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants