Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: minor editorial changes

Standard-layout types can be used to communicate with code written in other programming languages, as the layout of the type is strictly specified. The C++ Standard, [class], paragraph 7 [ISO/IEC 14882-2014], defines a standard-layout classes class as a class that

  • Does does not have virtual functions,
  • Has has the same access control for all nonstatic data members,
  • Has has no base classes of the same type as the first nonstatic data member,
  • Has has nonstatic data members declared in only one class within the class hierarchy, and
  • Recursivelyrecursively, does not have nonstatic data members of nonstandard-layout type.

...

This noncompliant code example assumes that there is a library whose header is library.h, and an application (represented by application.cpp), and that the library and application are not ABI-compatible. Therefore, the contents of library.h constitute an execution boundary. A nonstandard-layout type object S is passed across this execution boundary. The application creates an instance of an object of this type, then passes a reference to the object to a function defined by the library, crossing the execution boundary. Because the layout is not guaranteed to be compatible across the boundary, this results in unexpected behavior.

...