0

Summary

I am trying to compile an old C++ application on a new AIX 7 box with the AIX 11.1 compiler. This application uses offsetof on non POD classes.

I set the langlvl option to strict98 and also set the option for "offsetnonpod", which tells the compiler to allow offsetof on non-POD classes.

I get the same error if I remove the offsetnonpod setting and use extended for langlvl. It seems I must be doing something wrong with specifying the offsetnonpod option or the compiler doesn't actually support such functionality.

Example code

#include <iostream>

struct Foo
{
private:
    int x;
};

int main()
{
    std::cout << offsetof(Foo, x);
    return 0;
}

And I build with this command:

xlc++_r -qlanglvl=offsetnonpod -qlanglvl=strict98 test.cpp

And I get this:

"test.cpp", line 11.32: 1540-0287 (S) "offsetof" must not be applied to "struct Foo".  It is not a POD (plain old data) type.
Jonas
  • 121,568
  • 97
  • 310
  • 388

1 Answers1

0

The option changes the message from (S) to (W). The warning message will allow the compile to succeed and the offsetof is permitted.

Put -qlanglvl=strict98 first as that option will set -qlanglvl=nooffsetnonpod

xlC -qlanglvl=strict98 -qlanglvl=offsetnonpod a.cpp "a.cpp", line 11.18: 1540-1281 (W) "offsetof" cannot be applied to "struct Foo". It is not a POD (plain old data) type.

  • wow, thanks for pointing that out. That is cruel...change one character in a big message. I guess I'll be a lot more careful with reading in the future. – user1145530 May 01 '13 at 12:56