3 ms·
gcc -Wall does warn about comparison between signed and unsigned types, as well as comparisons that are always true/false due to limited type range.
by nitrogen 16y ago
gcc -Wall does warn about comparison between signed and unsigned types, as well as comparisons that are always true/false due to limited type range.
- JoachimSchipper 16y agoBut you can't really enable those warnings if you want to use -Werr, right? And I've always found the "always true/false due to limited range of data type" to be counterproductive. Something like int i; ... assert(i <= SSIZE_MAX); f(i); can make sense, but will cause gcc to complain if int and ssize_t happen to be the same size.
- JoachimSchipper 16y agoOf course, you should use ssize_t i and i <= INT_MAX...
- nitrogen 16y agoThere are ways of fixing the warnings so you can use -Werr. For signed/unsigned, just change the type of one side of the comparison, or cast to whichever type is most correct for the comparison while manually making sure that you won't have any range issues. For your limited range example, you could probably use the preprocessor: ssize_t i; #if SSIZE_MAX != INT_MAX assert(i <= INT_MAX); #endif /* SSIZE_MAX != INT_MAX */ f(i);