私はD言語を勉強していて、同時にC言語やC++言語と比較しています.dmdコンパイラとgdcコンパイラの両方でうまく動作しますが、gccコンパイラでテストしたところ、GCCコンパイラのバグboolean型の代わりに偽0 /次のコードを参照してくださいGCCコンパイラのブール型のC言語およびC++言語の初期化子は、0ではなく64です。コンパイラのバグですか?
C++コード
#include <iostream>
using namespace std;
int main()
{
bool b;
cout << b << endl;
return 0;
}
G ++コンパイラ(GCCバージョン4.4.3(Ubuntuの4.4.3-4ubuntu5.1):
をg++ -Wall -pedantic test.cpp
test.cpp: In function ‘int main()’: test.cpp:7: warning: ‘b’ is used
uninitialized in this function
./a.out 64
Cコード(foo.cの):
#include <stdio.h>
#include <stdbool.h>
#define bool _Bool
int main(int argc, char * args[])
{
bool b;
printf("%d\n", b);
return 0;
}
GCCコンパイラ
gcc-4.6 -Wall -pedantic a.c
foo.c: In function ‘main’:
foo.c:9:8: warning: ‘b’ is used uninitialized in this function [-Wuninitialized]
./a.out
64
TCCコンパイラ
tcc -Wall foo.c
./a.out
0
一族グラムコンパイラ
clang -Wall -pedantic foo.c
./a.out
0
誰かがgccの振る舞いを説明できますか?
ヒント:
C++ 11には、このかなりきれいになり、警告を見てください。 C++は、変数がデフォルトで何かに初期化されることを指定しません。 – Mysticial
誰かが-1を削除できますか?それは本当の質問です:( – Jack