我知道C 中的Binary Literal是從C 14標準化的。
但是,雖然我修復了stdas c 11,但它運行良好。因為實際上,我預計會出現錯誤。以下是我預計會出現錯誤的代碼。
int main(){
int a = 0b1010; // an error is expected
std::cout << a << std::endl;
}
另外,我已經使用以下命令編譯并執行了上述檔案。
g -std=c 11 -Wall main.cpp -o runfile
./runfile
沒有出現預期結果的原因是什么?有什么我做錯了嗎?
uj5u.com熱心網友回復:
早在 C 14 標準化之前,二進制文字就一直是 GCC 中的編譯器擴展。您可以編譯-pedantic以警告擴展并將-pedantic-errors這些特定警告提升為錯誤:
<source>:3:11: error: binary constants are a C 14 feature or GCC extension
3 | int a = 0b1010; // an error is expected
| ^~~~~~
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/392251.html
