From 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 7 Apr 2024 13:41:34 -0500 Subject: new repository --- devdocs/c/language%2F_alignof.html | 51 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 devdocs/c/language%2F_alignof.html (limited to 'devdocs/c/language%2F_alignof.html') diff --git a/devdocs/c/language%2F_alignof.html b/devdocs/c/language%2F_alignof.html new file mode 100644 index 00000000..1a478589 --- /dev/null +++ b/devdocs/c/language%2F_alignof.html @@ -0,0 +1,51 @@ +

_Alignof operator (since C11) +

Queries the alignment requirement of its operand type.

+

Syntax

+ + +
_Alignof( type-name ) (since C11)
alignof( type-name ) (since C23)
+ +

This operator is typically used through the convenience macro alignof, which is provided in the header <stdalign.h>

+
(until C23)

Explanation

Returns the alignment requirement of the type named by type-name. If type-name is an array type, the result is the alignment requirement of the array element type. The type-name cannot be function type or an incomplete type.

+

The result is an integer constant of type size_t.

+

The operand is not evaluated (so external identifiers used in the operand do not have to be defined).

+

If type-name is a VLA type, its size expression is not evaluated.

+

Notes

The use of _Alignof(until C23)alignof(since C23) with expressions is allowed by some C compilers as a non-standard extension.

+

Keywords

alignof, _Alignof

+

Example

#include <stdalign.h>
+#include <stddef.h>
+#include <stdio.h>
+ 
+int main(void)
+{
+    printf("Alignment of char = %zu\n", alignof(char));
+    printf("Alignment of max_align_t = %zu\n", alignof(max_align_t));
+    printf("alignof(float[10]) = %zu\n", alignof(float[10]));
+    printf("alignof(struct{char c; int n;}) = %zu\n",
+            alignof(struct {char c; int n;}));
+}

Possible output:

+
Alignment of char = 1
+Alignment of max_align_t = 16
+alignof(float[10]) = 4
+alignof(struct{char c; int n;}) = 4

Defect reports

The following behavior-changing defect reports were applied retroactively to previously published C standards.

+ + + +
DR Applied to Behavior as published Correct behavior
+DR 494 C11 whether the size expression in a VLA is evaluated in _Alignof was unspecified it is unevaluated

References

See also

+ + +
+
(C11)
a type with alignment requirement as great as any other scalar type
(typedef)
_Alignas specifier(C11) sets alignment requirements of an object
C++ documentation for alignof operator
+

+ © cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
+ https://en.cppreference.com/w/c/language/_Alignof +

+
-- cgit v1.2.3