英特尔编译器 - 错误:标识符“alignof”未定义

时间:2013-07-15 15:18:40

标签: c++ compilation compiler-errors icc compiler-specific

我正在尝试运行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' ;
}

当我用gcc(g ++ -std = c ++ 11 alignof.cpp)编译它时,我没有错误。 但是当我用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' ;

我在同一台机器上运行代码,并使用module命令更改编译器。 如何定义alignof运算符?

1 个答案:

答案 0 :(得分:3)

不同的编译器对2011年推出的新语言功能有不同的支持。

根据this table,英特尔的编译器尚不支持alignof