News for hackers. Stuff that matters.
Re:Subtraction is not comparison by gonzo on Thursday December 25, 2014 @10:15PM (#8797892)
Someone needs to explain to Teddy how the compiler implements subtraction.

Hint: his example is fine (and thus, Ted is wrong).

But, since Ted is OpenBSD.. here come the downvotes.

As the poster below states, the example in the last link of Ted's posting has overflow problems.

Re:Subtraction is not comparison by cremno on Thursday December 25, 2014 @10:39PM (#8797939)
You should read the post again and then open the last link. Then tell us again that the example is fine.
Re:Subtraction is not comparison by gonzo on Thursday December 25, 2014 @10:51PM (#8797975)
Last link is just someone being stupid.
Re:Subtraction is not comparison by cremno on Friday December 26, 2014 @01:05AM (#8798216)
Then why isn't his example stupid, but fine? They're basically doing the same bad thing - subtracting two signed integers without caring about possible overflow.
Re:Subtraction is not comparison by imron on Thursday December 25, 2014 @11:04PM (#8798005)
Doesn't seem so fine to me..

  /*compare.c*/
  #include <stdio.h>
  
  int compare( int x, int y )
  {
      return x - y;
  }
  
  void testCompare( int x, int y )
  {
      if ( compare( x, y ) < 0 )
      {
          printf( "%d is less than %d\n", x, y );
      }
      else
      {
          printf( "%d is greater than or equal to %d\n", x, y );
      }
  }
  
  int main()
  {
      testCompare( 5, 10 );
      testCompare( 10, 5 );
      testCompare( 1987654321, -1987654321 );
      return 0;
  }
$ clang -o compare compare.c

$ ./compare

5 is less than 10

10 is greater than or equal to 5

1987654321 is less than -1987654321