alignof is defined in stdalign.h
for gcc
:
$ cat /usr/lib/gcc/x86_64-unknown-linux-gnu/9.1.0/include/stdalign.h
......
#ifndef _STDALIGN_H
#define _STDALIGN_H
#ifndef __cplusplus
#define alignas _Alignas
#define alignof _Alignof
#define __alignas_is_defined 1
#define __alignof_is_defined 1
#endif
#endif /* stdalign.h */
To use alignof
, stdalign.h
must be included, otherwise following errors will be reported:
......
warning: implicit declaration of function 'alignof' [-Wimplicit-function-declaration]
3 | return alignof(int);
| ^~~~~~~
error: expected expression before
It is no need to include any header files to use _Alignof
and __alignof__
.