2013-07-15 2 views
4

저는 alignof 연산자의 예제를 실행하려고합니다. 내가 GCC (g ++ -std = C++ 11 alignof.cpp)로 컴파일 할 때인텔 컴파일러 오류 : "alignof"식별자가 정의되지 않았습니다.

#include <iostream> 

struct Empty {}; 

struct Foo { 
    int f2; 
    float f1; 
    char c; 
}; 

int main() 
{ 
    std::cout << "alignment of empty class: " << alignof(Empty) << '\n' 
       << "alignment of pointer : " << alignof(int*) << '\n' 
       << "alignment of char : "  << alignof(char) << '\n' 
       << "alignment of Foo : "  << alignof(Foo) << '\n' ; 
} 

나는 오류를 얻을 수 없습니다. 하지만 ICC (ICPC -std = C++ 11 alignof.cpp) 나는 다음과 같은 오류를 얻을 수 및 이유를 모르겠어요 함께 컴파일 할 때 : 나는 같은에 코드를 실행 해요

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' ; 

machine, module 명령으로 컴파일러를 바꾼다. 어떻게 alignof 연산자를 정의 할 수 있습니까?

+0

인텔 컴파일러에서 지원되는 것이 확실합니까? C++ 11 스위치를 사용하는 것이 한 가지이지만, 구현하지 않은 경우 여기에 무엇을 얻는 지 설명합니다. – Borgleader

+0

글쎄, 그게 틀림 없어. 고맙습니다! – dspereira004

답변

3

다른 컴파일러는 this table에 따르면, 인텔의 컴파일러는 아직 alignof를 지원하지 않습니다 2011 년

에 도입 된 새로운 언어 기능에 대해 서로 다른 지원합니다.

+0

안녕하세요, 맞습니다. alignof가 지원되지 않는다는 것을 알지 못했습니다. 고맙습니다! – dspereira004

+0

ICC를위한 내부 매크로 또는 이와 유사한 것이 있습니까? 내가 아는 현대의 모든 컴파일러는 특정 키워드를 알아야합니다. – jww

+0

@jww : [this] (https://software.intel.com/en-us/forums/intel-c-compiler/topic/281802)를 찾으십니까? – jadelord

관련 문제