5 ms·
> It's a warning not an error. Many build environments are set to treat all warnings as errors. The point is that 2^32 is a perfectly compliant C expression t
by NotPaidToPost 7y ago
> It's a warning not an error.
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?
- lifthrasiir 7y agoLike it or not, there are already tons of lint-like warnings in GCC [1] and clang [2]. Many (uh, most?) of them are not required by the C/C++ standards (which by the way have their own requirements for diagnostic messages). [1] https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html [2] https://clang.llvm.org/docs/DiagnosticsReference.html https://clang.llvm.org/docs/DiagnosticsReference.html
- stestagg 7y agoEnvironments where the decision has been made that error-prone, misleading and ambiguous statements should not be allowed typically are those where warning are treated as errors. A new type of misleading and error-prone statement has been found, so it seems entirely reasonable that this is added to that list. This seems to be the entire intent of compiler warnings (these days anyway)
- pjc50 7y agoThe compiler should complain because it's overwhelmingly likely to be a mistake.
- barrkel 7y agoPlenty of valid expressions generate warnings. A frequent gotcha is `=` in boolean contexts. Warnings are justified, and can normally be avoided with a little bit more lexical work (e.g. an extra set of parentheses). The upside is large and the downside is miniscule.
- OskarS 7y agoIsn't that pretty much the definition of a warning? An expression that is technically valid, but probably a mistake. If something wasn't a valid expression, it would be a compiler error, not a warning.
- mikeash 7y agoUsually, yes. C is weird because undefined behavior is illegal, can sometimes be detected statically, and yet will not produce an error. So sometimes you get warnings for invalid yet error-free code. It’s a strange language.
- viraptor 7y agoYou can turn specific warnings off. You can also usually disable them inline. There are very common ways to deal with false positive warnings.
- sayusasugi 7y agoHeuristics like this are important because humans are not machines. If you run into a warning in one of these situations, they are usually rectified by changing the statement slightly. Worst case scenario you can #pragma push and pop the warning.