我使用Eclipse CDT - 在Windows 7上跨G ++編者(MinGW的/ MSYS),這是我的代碼:的int64_t溢出問題
int64_t y = 1024 * 1024 * 1024 * 4;
std::cout << "type id: " << typeid(y).name() << "; value: " << y << "; size of y: " << sizeof(y) << std::endl;
(IDE會警告: 「整數溢出」。)
輸出是:
"type id: x; value: 0; size of y: 8"
我不明白,爲什麼Y的大小爲8個字節,但值爲0
感謝您的幫助。
'1024'類型爲'int',它可以是也可以不是32位,可以是也可以不是4個字節。 –
在「Eclipse CDT,Cross G ++ Complier」中,「int」的大小沒有「可能或不可能」,並且它總是一些不變的數字,最可能是4個字節。但是,是的,C++標準沒有指定「int」的大小,由編譯器決定。 –
一個小點:外括號是不必要的:'int64_t y =(int64_t)1024 * 1024 * 1024 * 4;' –