3 ms·
Two additions: 1) -Wall -Werr does not note type conversions (indeed, it could not, because they are necessary - just dangerous. -1 < 0U is usually not true!)
by JoachimSchipper 16y ago
Two additions:
1) -Wall -Werr does not note type conversions (indeed, it could not, because they are necessary - just dangerous. -1 < 0U is usually not true!)
3) Casting is very much necessary with function taking a variable number of arguments.
But yes, modern tools and C90/C99 help a lot.
- nitrogen 16y agogcc -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);