Don't enforce the U suffix when it's not necessary #617
Replies: 1 comment
-
IntegerAFAIK: The rule of the compiler is basically that it uses the smallest type that fits the literal The only effect of the This is well-defined
and equivalent to We do not have the latter issue. Even It is always problematic to assign a type with larger bit-with to a smaller one (such as In no case that I can imagine or occurs in the code base the addition of FloatFor floating point numbers it is a different game and assigning floats literals to double is different than assigning the same double literal (the values are different in general due to the way floats work!) This means if a floating point literal is desired, the For this reason I support @elBoberido in this case. If it is not required by some standard we should not make unsigned literals mandatory. I would argue that the standard is bad if it requires something like this and it would need a very good reason to convince me otherwise. Note that narrowing conversions always need a cast and the corresponding logic needs to ensure they are safe (the compiler can generally not know this). |
Beta Was this translation helpful? Give feedback.
-
I have the feeling that the U suffix is getting out of control and it's not even necessary.
The first exception to MISRA rule 10.3 is this
https://www.misra.org.uk/LinkClick.aspx?fileticket=-BRmxs8omoM%3d&tabid=57
This means it's perfectly fine to use
uint32_t foo = 0;
oruint32_t bar = 42;
.Therefore I propose to make use of this exception and don't enforce the U suffix where it's not necessary.
@budrus @MatthiasKillat @dkroenke @marthtz @FerdinandSpitzschnueffler @ithier @mossmaurice @elfenpiff
Beta Was this translation helpful? Give feedback.
All reactions