-
-
Notifications
You must be signed in to change notification settings - Fork 968
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
Fix unsigned/signed comparison warning in Metronome.cpp #669
Fix unsigned/signed comparison warning in Metronome.cpp #669
Conversation
The assert is not ideal in this scenario. It would be better to turn BPM into an |
The best solution IMO would be to promote bpm to a uint32_t before the comparision. There would be no loss of information this way and it would eliminate the warning. |
@evergreen22 why the unnecessary precision? |
The problem as I understand it as a uint32_t is being compared to a
uint16_t. This causes a compiler warning.
Possible solutions are:
* convert the 32 bit value to 16 bit
* convert the 16 bit value to 32 bit
* ignore the warning
* change the declared types to match
The best choice is the last one. However, if we don't want to do that I
think the next safest choice is the second one. Internally all
comparisions are done with ints so that is why I suggested promotion.
I would note that there is a risk of hitting undefined behavior with
unsigned variables and promotion that may result in undefined behavior
depending on how the compiler handles promotion of unsigned ints. IDK if
that is a problem with our compiler.
“There are far too many integer types, there are far too lenient rules for
mixing them together, and it’s a major bug source, which is why I’m saying
stay as simple as you can, use [signed] integers til you really really
need something else.” -Bjarne Stroustrup
|
Well it kinda is the only choice if I'm being totally honest. The goal of the warning or removal of it shouldn't be simply getting rid of the warning, but to warn against and fix inconsistencies in integer typing. |
as clarification: the warning is about the signed int ( I've change the When getting the int16_t lv_arc_get_value(const lv_obj_t * arc) When setting the arc-value convert from void lv_arc_set_value(lv_obj_t * arc, int16_t value) |
757df27
to
78740b1
Compare
I don't think bpm type should be changed. LVGL works with 16 bit ints and TickType_t is 32 bit uint, so they have to mix at some point. If we change bpm type, we have to cast it everywhere instead of just at the one point. The first commit was fine, just without the assert. |
`xTaskGetTickCount()` returns a `TickType_t`, which is defined as an `uint32_t`. This is compared to the `bpm` variable, which is a `int16_t` in the range of 40 to 220 as defined in the constructor. ```cpp lv_arc_set_range(bpmArc, 40, 220); ``` Just assume that `bpm` is greater than 0, as this would result in a divison by zero or negative values, which would unintentionally underflow to a very large number.
78740b1
to
63477fc
Compare
@Riksu9000 updated |
Thanks! |
xTaskGetTickCount()
returns aTickType_t
, which is defined as anuint32_t
. This is compared to thebpm
variable, which is aint16_t
in the range of 40 to 220 as defined in the constructor.
Just to be sure also add an assert that
bpm
is greater than 0, as thiswould result in a division by zero or negative values, which would
unintentionally underflow to a very large number.
Not flashed, I have only a sealed watch and I'm afraid of bricking it