std::max_align_t

From cppreference.com
< cpp‎ | types
 
 
Utilities library
General utilities
Date and time
Function objects
Formatting library (C++20)
(C++11)
Relational operators (deprecated in C++20)
Integer comparison functions
(C++20)(C++20)(C++20)   
(C++20)
Swap and type operations
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
Common vocabulary types
(C++11)
(C++17)
(C++17)
(C++17)
(C++11)
(C++17)
(C++23)
Elementary string conversions
(C++17)
(C++17)
 
Type support
Basic types
Fixed width integer types (C++11)
Fixed width floating-point types (C++23)
max_align_t
(C++11)    
(C++17)
Numeric limits
C numeric limits interface
Runtime type information
 
Defined in header <cstddef>
typedef /*implementation-defined*/ max_align_t;
(since C++11)

std::max_align_t is a trivial standard-layout type whose alignment requirement is at least as strict (as large) as that of every scalar type.

Notes

Pointers returned by allocation functions such as std::malloc are suitably aligned for any object, which means they are aligned at least as strictly as std::max_align_t.

std::max_align_t is usually synonymous with the largest scalar type, which is long double on most platforms, and its alignment requirement is either 8 or 16.

Example

#include <iostream>
#include <cstddef>
int main()
{
    std::cout << alignof(std::max_align_t) << '\n';
}

Possible output:

16

References

  • C++23 standard (ISO/IEC 14882:2023):
  • 17.2.4 Sizes, alignments, and offsets [support.types.layout] (p: 504-505)
  • C++20 standard (ISO/IEC 14882:2020):
  • 17.2.4 Sizes, alignments, and offsets [support.types.layout] (p: 507-508)
  • C++17 standard (ISO/IEC 14882:2017):
  • 21.2.4 Sizes, alignments, and offsets [support.types.layout] (p: 479)
  • C++14 standard (ISO/IEC 14882:2014):
  • 18.2 Types [support.types] (p: 443-444)
  • C++11 standard (ISO/IEC 14882:2011):
  • 18.2 Types [support.types] (p: 454-455)

See also

alignof operator(C++11) queries alignment requirements of a type
obtains the type's alignment requirements
(class template)
(C++11)
checks if a type is a scalar type
(class template)