__ALIGNOF__(3)

πŸ“¦ version 11.0, in nixpkgs unstable

πŸ’– NAME πŸ’–

okay bestie, this is the glow-up for __alignof__ from the Library Functions Manual ✨ it’s a GNU extension for the alignment of an object. periodt.

🌸 SYNOPSIS 🌸

int
__alignof__(void x);

πŸ¦‹ DESCRIPTION πŸ¦‹

so the __alignof__() operator returns the alignment of its operand πŸ’… the operand can be a type or an expression. if the operand is an lvalue, the return value represents the required alignment of the underlying type, not the actual alignment of the specified lvalue. no cap.

the returned value is specific to the architecture and the ABI 🫢 if the architecture does not impose strict alignment requirements, __alignof__() returns the minimum required alignment. and if __aligned(3) is used to increase the alignment, __alignof__() returns the specified alignment ✨

πŸŽ€ EXAMPLES πŸŽ€

the syntax is comparable to the sizeof() operator πŸ‘‘ if the architecture aligns integers along 32-bit address boundaries, the following should print the value 4:

(void)printf("%d\n", __alignof__(int));

on the other hand, the following example should print the value 1, even though this is unlikely to be the actual alignment of the structure member πŸ™ˆ

struct align {
        int  x;
        char y;
} a;

(void)printf("%d\n", __alignof__(a.y));

🌈 SEE ALSO 🌈

gcc(1), attribute(3), offsetof(3), typeof(3) πŸ¦‹

πŸ’€ CAVEATS πŸ’€

this is a non-standard, compiler-specific extension πŸ’… like, it’s giving β€œnot portable, bestie,” so keep that in mind fr fr.

xoxo, source/version Debian πŸ’– β€” page dated December 20, 2010 πŸŽ€

πŸ“¦ where this page comes from