_Alignof C11 alignment query
_Alignof C11 alignment query
C11's _Alignof returns a complete type's alignment as size_t for type names, not expressions. Arrays yield element alignment; values are ABI-dependent.
| Category | C11 features |
|---|---|
| Kind | Keyword / Statement |
| C standard | C11 |
📝 Syntax
_Alignof(double) /* Usually 8 */
▶ Example
Edit the C code below and click Run; the server compiles and executes it:
Output:
alignof(double) = 8
alignof(char) = 1
ℹ️ Info alignof(double) = 8 is the output of the common x86-64 GCC 10.2 ABI, while alignof(char) = 1 follows from the basic type's alignment rules. double alignment depends on the target ABI and should not be hard-coded as a portable constant.
🏷️ Related C11 features
📚 Related Tutorials
❓ FAQ
QWhy doesn't _Alignof(double) necessarily return 8?
AAlignment is determined by the implementation and target ABI, not by double's object size. Even if double occupies 8 bytes, some 32-bit ABIs require only 4-byte alignment.
QDo _Alignof and sizeof query the same thing?
ANo. sizeof reports how many bytes an object occupies, while _Alignof reports the alignment in bytes required for its starting address. An 8-byte type might have alignment 4, 8, or another value.
QCan a variable name be written directly after _Alignof?
AStandard C11 requires a type name in parentheses, not an arbitrary expression. To query an object's type, write that type or use a standard mechanism such as _Generic; typeof is a compiler extension.