2013-07-15 132 views
4

我試圖運行一個alignof運算符的例子。當我用gcc編譯它(g ++ -std = C++ 11 alignof.cpp)時,我得不到任何錯誤。 但是,當我使用ICC(ICPC -std = C++ 11 alignof.cpp)我收到以下錯誤,我不知道爲什麼編譯:英特爾編譯器 - 錯誤:標識符「alignof」未定義

cenas.cpp(13): error: type name is not allowed 
     std::cout << "alignment of empty class: " << alignof(Empty) << '\n' 
                 ^

cenas.cpp(13): error: identifier "alignof" is undefined 
     std::cout << "alignment of empty class: " << alignof(Empty) << '\n' 
               ^

cenas.cpp(14): error: type name is not allowed 
       << "alignment of pointer : " << alignof(int*) << '\n' 
                 ^

cenas.cpp(14): error: expected an expression 
       << "alignment of pointer : " << alignof(int*) << '\n' 
                  ^

cenas.cpp(15): error: type name is not allowed 
       << "alignment of char : "  << alignof(char) << '\n' 
                 ^

cenas.cpp(16): error: type name is not allowed 
       << "alignment of Foo : "  << alignof(Foo) << '\n' ; 

我在同一個運行的代碼機器,我用模塊命令更改編譯器。 alignof運算符如何定義?

+0

你確定它是由intel編譯器支持的嗎?擁有C++ 11開關是一回事,但如果他們從未實現它,這就解釋了你在這裏得到了什麼。 – Borgleader

+0

嗯,一定是這樣的。謝謝! – dspereira004

回答

3

不同的編譯器必須在2011年

介紹根據this table,英特爾的編譯器還不支持alignof新語言特性不同的支持。

+0

嗨,這很有道理,我不知道alignof不被支持。謝謝! – dspereira004

+0

是否有ICC的內部宏或類似內容?我知道所有的現代編譯器都有它,你只需要知道具體的關鍵字。 – jww

+0

@jww:您是否在尋找[this](https://software.intel.com/zh-cn/forums/intel-c-compiler/topic/281802)? – jadelord