alignof Operator (C++11)

From RAD Studio
Jump to: navigation, search

Go Up to C++11 Features in the Classic Compiler


Attention: This page refers to a C++11 feature in the Classic compiler. The Classic compiler is not recommended: instead it is recommend you use the Clang-enhanced compilers, which support modern C++ including C++11, C++14 and C++17.

The C++11 standard includes the alignof keyword and operator, which tells you the alignment of a type.

To get the alignment of a type, use the following syntax:

alignof(type);

The result is an integer constant of type std::size_t. The value indicates the boundaries on which elements of that type are aligned in memory. For instance, an alignment of 2 means that the type must begin on even memory addresses. A typical value for alignof (double) might be 8.

Applying alignof to a reference type yields the alignment of the referenced type. If you apply alignof to an array type, you get the alignment of its element's type.

See Also