Question

I'm trying to run an example of the alignof operator.

#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'm running the code on the same machine, and I change compilers with the module command. How can the alignof operator be undefined?

Was it helpful?

Solution

Different compilers have different support for the new language features introduced in 2011.

According to this table, Intel's compiler does not yet support alignof.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top