OliverBr wrote:michiguel wrote:
If you turn on the warnings, most C compilers will scream if they see (A & B == C) rather than ((A & B) == C).
Miguel
Neither gcc, nor Visual Studio complained about it (with warnings on, of course).
You are right
Code: Select all
#include <stdio.h>
#define PIECE(m) m
#define TO(m) m
#define PAWN 1
int main (void)
{
int m=1;
int ext = 0;
#if 1
if (PIECE(m) == PAWN && ((TO(m) & 48) == 48 || TO(m) & 48) == 0) ext++;
#else
if (PIECE(m) == PAWN && ((TO(m) & 48) == 48 || (TO(m) & 48) == 0)) ext++;
#endif
printf ("ext=%d\n", ext);
return 0;
}
GCC gives no warning in either case with
gcc -Wall -Wextra temp.c -o temp
However splint detects it
First version:
Code: Select all
Splint 3.1.2 --- 07 May 2008
temp.c: (in function main)
temp.c:13:36: Right operand of || is non-boolean (int):
(m & 48) == 48 || m & 48
The operand of a boolean operator is not a boolean. Use +ptrnegate to allow !
to be used on pointers. (Use -boolops to inhibit warning)
Finished checking --- 1 code warning
Corrected version:
Code: Select all
Splint 3.1.2 --- 07 May 2008
Finished checking --- no warnings
This must be some sort of pathological case for the warning detection. As I said, if I include
if (TO(m) & 48 == 0)
ext++;
I get with gcc -Wall -Wextra temp.c -o temp
temp.c: In function ‘main’:
temp.c:17: warning: suggest parentheses around comparison in operand of &
Miguel
PS: Note to myself => I have to keep using splint!!