Vin*_*982 1 c gcc mingw parentheses
我试图检查这是否等于零
//Address already malloc
void MyCheck (void *Address){
if ( (long)Address & (~(sizeof(long)-1)) != 0 ){
printf("Invalid");
}
}
Run Code Online (Sandbox Code Playgroud)
当试图编译它给我:
Error: suggest parentheses around comparison in operand
of '&' [-Werror=parentheses]
Run Code Online (Sandbox Code Playgroud)
!=优先级高于&,所以你的代码实际上是这样的:
if ((long)Address & ( (~(sizeof(long)-1)) != 0 ) )
^ ^
Run Code Online (Sandbox Code Playgroud)
gcc建议这可能是一个错误,它可能是.你想要:
if ( ( (long)Address & (~(sizeof(long)-1)) ) != 0 )
^ ^
Run Code Online (Sandbox Code Playgroud)