【C言語】
bool型の不適切な使い方
こんな使い方は避けたい

bool型++ してはいけない warning: increment of a boolean expression bool型--

■bool型を++/--してはいけない

warning: increment of a boolean expression

警告:真偽値(0/1)しか取れないbool型を加算した
[-Wbool-operation]

#include <stdbool.h>
#include <stdio.h>
//gcc/clang     --トグル               ++カウンターストップ
//VS2022        --カウンターストップ    ++カウンターストップ
int main(void){
    bool a = true;
    bool b = false;
    bool c = true;
    bool d = false;
    for(int i = 0; i < 10 ; i++){
        printf("%d:%d:%d:%d\n",a--,b--,c++,d++);
    }
}

0/1しか取れない bool 型変数を
++/--するのは多分誤りと思われます。

➡gcc/clangの結果

1:0:1:0
0:1:1:1
1:0:1:1
0:1:1:1
1:0:1:1
0:1:1:1
1:0:1:1
0:1:1:1
1:0:1:1
0:1:1:1

先のプログラムをgccでコンパイルして動かすと上記になります。
ーー演算子がトグルになりますが、
これを利用しようとしてはいけません。


➡トグルの実装(推奨)

#include <stdbool.h>
#include <stdio.h>
//トグルの実装bool型でなくても可能  
int main(void){
    bool a = true;
    bool b = false;
    for(int i = 0; i < 10 ; i++){
        printf("%d:%d\n",a=1-a,b=1-b);
    }
}

このように記述すると
コンパイラに依存せずにトグルを実装できます。

非推奨だった bool 型に対するインクリメント演算子を削除

https://cpprefjp.github.io/lang/cpp17/remove_deprecated_increment_of_bool.html

[-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項演算子を使うのは
間違えの可能性があります。