Le 14/05/2025 à 10:45, John Paul Adrian Glaubitz a écrit :
Hi Laurent,
On Wed, 2025-05-14 at 10:10 +0200, Laurent Vivier wrote:
You can use __alignof__() to have the data type alignment:
int main(void)
{
printf("alignof(short) %ld\n", __alignof__(short));
printf("alignof(int) %ld\n", __alignof__(int));
printf("alignof(long) %ld\n", __alignof__(long));
printf("alignof(long long) %ld\n", __alignof__(long long));
}
On x86_64, it gives:
alignof(short) 2
alignof(int) 4
alignof(long) 8
alignof(long long) 8
Is alignof() supported in ancient versions of GCC and the Sun compiler?
Since GCC 2.x (1992)
https://gcc.gnu.org/onlinedocs/gcc-2.95.3/gcc_4.html#SEC89
It's a gcc extension.
For other compilers, we need to use _Alignof() from C11.
Thanks,
Laurent