-
Notifications
You must be signed in to change notification settings - Fork 237
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
spi/pwm: fix "uninitialized" warnings #51
base: devel
Are you sure you want to change the base?
Conversation
@Livius90 thanks for the PR. My only concerns are that we shouldn't add |
It is practical to provide an initialize value for an enum type variable. pwm_polarity_t polarity = PWM_POLARITY_INVALID; What do you prefer to use for initialize an enum variable? If just zero would use, it means it will be initialized for the first enum value. In a more complex code it can cause any issue. pwm_polarity_t polarity = 0; /* PWM_POLARITY_NORMAL */ |
It's not practical to put the invalid state after a bunch of valid ones. That's not only confusing, but also breaks the enum for any future additions. I agree with your latter suggestion -- that we might as well just explicitly initialize to 0 (whichever state it corresponds to). |
Do you mean the typedef enum pwm_polarity {
PWM_POLARITY_INVALID,
PWM_POLARITY_NORMAL, /* Normal polarity */
PWM_POLARITY_INVERSED, /* Inversed polarity */
} pwm_polarity_t; What do you prefer now, i can change to use pwm_polarity_t polarity = 0; /* PWM_POLARITY_NORMAL */
...
spi_bit_order_t bit_order = 0; /* MSB_FIRST */ |
Yup, exactly. This would have been ideal, but at this point I don't think it's a good idea to break the API.
Yeah, this is a good compromise for now. I don't think the comment is actually needed, and it might even be a bit confusing, because the intention is just to give the variable an initialized value rather than set it to the state described in the comment. |
@vsergeev |
@vsergeev |
Hmm... I'm not seeing these warnings under GCC 14.2.1 or Clang 18.1.8. Are you still getting the warning? I'm also a little concerned because there are many more uninitialized stack variables in other modules than the ones covered in these commits. |
91246ed
to
911e989
Compare
In my cross-compiler buildflow i use GCC 13.3.0 and cmake is changed to use latest C and C++ standard (much newer then gnu99) and i still have the wranings if i not fix them via a patch. You can not get this warning in any other uninitialized stack variables because in the other code parts they got any |
I'm not ready to advance the C standard beyond As for the uninitialized variable changes, I'm not opposed to those in principle. |
You can see more and important warnings if you increasing the C standard. Because it is now 2025, i thought it should be the right time to get much better than |
Fix "uninitialized" warnings which can produced in case of use GCC v12.3.0 with
-Wall -Wextra
arguments.