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

4

我正在尝试运行一个关于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' ;

我正在同一台机器上运行代码,并使用模块命令更改编译器。 如何将alignof操作符未定义?


你确定这是Intel编译器支持的吗?拥有c++11开关只是一回事,但如果他们从未实现它,那就可以解释你在这里遇到的问题了。 - Borgleader
好的,一定是这样。谢谢! - dspereira004
1个回答

3

不同的编译器对于2011年引入的新语言特性的支持程度有所不同。

根据这个表格,英特尔的编译器目前还不支持alignof


嗨,那很有道理,我不知道alignof不受支持。谢谢! - dspereira004
有没有 ICC 的内部宏或类似功能?我知道所有现代编译器都有这个功能,你只需要知道具体的关键字。 - jww
@jww:你是否在寻找这个 - jadelord

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接