(no title)
NotPaidToPost | 6 years ago
Better to leave this to code analysis tools.
Edit:
2^32 uses the ^ operator exactly as intended, and has perfectly legitimate uses, especially when dealing with registers of HW peripherals.
It's not the same as warning on "if (a=b)" as someone replied.
From a language perspective, 2^32 is exactly the same as 2+32.
rocqua|6 years ago
raxxorrax|6 years ago
Mostly written as y ^ (1 << x), which could easily resolve to these expressions. Mostly at runtime, sure, but there are exceptions. Especially if you like descriptive constants. I would expect it to be quite difficult to separate the "correct cases" without people starting to just suppress compiler warnings or trick it with writing the same stuff in different words (which might be better).
On the other hand, setting max_short to something like 18 is probably a really god prank in larger programming environments. The compiler would just ruin all the fun here.
pmikesell|6 years ago
NotPaidToPost|6 years ago
Many build environments are set to treat all warnings as errors.
The point is that 2^32 is a perfectly compliant C expression that is neither misleading nor ambiguous, and that also won't create any variable overflow. It uses ^ exactly as intended. Why should the compiler complain? Why should I get a warning/error when following the spec to the letter?
masklinn|6 years ago
"if (a=b)" uses the "=" operator exactly as intended with perfectly legitimate uses. It's warned about because it's an error-prone construct, not because it's incorrect.
Seems to me 2^32 is also error-prone, if you wanted to combine flags you'd use 2|32, using xor here is weird.
NotPaidToPost|6 years ago
On the other hand ^ expects integers so 2^32 is exactly what is expected.
Most the replies I saw here try to second-guess or claim that ^ should be used in a specific way. Not so, ^ is just doing XOR of two integers.
Apparently, I am having an incorrect opinion, though, so I will self-censor and remain silent.
blattimwind|6 years ago
There are many technically valid expressions and statements that will still generate warnings in most compilers.
if(a=b) {} comes to mind first and foremost.
estebank|6 years ago
__david__|6 years ago
NotPaidToPost|6 years ago
Stating that 32^2 should not trigger a warning while 2^32 should shows that this proposal has not been thought through.
It's not desirable or sensible to raise a warning on the premise that the expression might mean something else in another language, which is what this would do.