Intel Compiler - error: identifier "alignof" - undefined
I am trying to run an example alignof statement.
#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' ; } When I compile it with gcc (g ++ -std = C ++ 11 alignof.cpp), I get no errors. But when I compile it with icc (icpc -std = c ++ 11 alignof.cpp), I get the following errors, and I don't know why:
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' ; I run the code on the same computer, and I change the compilers with a module command. How is the alignment operator undefined?
Different compilers have different support for the new language features introduced in 2011.
According to this table , the Intel compiler does not yet support alignof .