News for hackers. Stuff that matters.
Re:The Ten Commandments for C Programmers (Annotated Edition) by nitrogen on Saturday November 06, 2010 @06:56PM (#1877979)
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.
Re:The Ten Commandments for C Programmers (Annotated Edition) by JoachimSchipper on Sunday November 07, 2010 @06:06AM (#1879140)
But 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.
Re:The Ten Commandments for C Programmers (Annotated Edition) by nitrogen on Monday November 08, 2010 @06:49PM (#1884565)
There 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);
Re:The Ten Commandments for C Programmers (Annotated Edition) by JoachimSchipper on Sunday November 07, 2010 @10:36AM (#1879529)
Of course, you should use ssize_t i and i <= INT_MAX...