You should read the post again and then open the last link. Then tell us again that the example is fine.
Last link is just someone being stupid.
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.
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
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.