FreeBSD の LLVM で C 言語の整数型リテラル値と整数型定数の論理和を試す ― 2018年09月25日 11時12分26秒
さて、今度は整数型定数の論理和を行い、LLVM がどのような動作をするか確かめる。
こちらも、リテラル値やマクロ定数と同じ報告がされた。
freebsd% cat logical-and-const-int.c
const int magic = 2;
int main()
{
return 1 && magic;
}
freebsd% cc logical-and-const-int.c
logical-and-const-int.c:4:14: warning: use of logical '&&' with constant operand
[-Wconstant-logical-operand]
return 1 && magic;
^ ~~~~~
logical-and-const-int.c:4:14: note: use '&' for a bitwise operation
return 1 && magic;
^~
&
logical-and-const-int.c:4:14: note: remove constant to silence this warning
return 1 && magic;
~^~~~~~~~
1 warning generated.
freebsd%
どうも定数の値が利用時に見えているから報告するようだ。もう少し趣向を変えてみる。定数の定義を論理和の後に持っていく。
今度は何の警告や文句もなくコンパイル終了。コンパイラはわざわざ二パスを行ってまで、報告するわけではないようだ。
freebsd% cat logical-and-const-int2.c
extern const int magic;
int main()
{
return 1 && magic;
}
const int magic = 2;
freebsd% cc logical-and-const-int2.c
freebsd%
FreeBSD 11.2-RELEASE の LLVM 6.0.0 で実験。
最近のコメント