【C言語】
【<】と【<<】を間違える

warning: ‘<<’ in boolean context, did you mean ‘<’?

warning: converting the result of ‘<<‘ to a boolean; did you mean ‘(x << y) != 0’?

警告:<<でなくて<では?

[-Wint-in-bool-context]


■【<】と【<<】の間違い

#include <stdio.h>
char *f(int x,int y){
    if(x << y)  //バグ? if(x<y)
        return  "x<y";
    else
        return  "x>=y";
}
int main(void){
    printf("%s\n",f(1,2));
    printf("%s\n",f(2,1));
}

if(x<<y)と
if(x<y)を間違えた可能性があります。


■三項演算子の間違い

warning: ‘?:’ using integer constants in boolean context, the expression will always evaluate to ‘true’

#include <stdio.h>
char *f(int x,int y){
    if(x < y ? 1 : 2)   //バグ?
        return  "真";
    else
        return  "偽";
}
int main(void){
    printf("%s\n",f(1,2));
    printf("%s\n",f(2,1));
}

if文の中で3項演算子を使うのは
間違えの可能性があります。