fuhsnn / slimcc

C11 compiler with GNU / C23 extensions for x86-64 Linux, able to build Python and PostgreSQL
MIT License
24 stars 3 forks source link

`_Alignof [expression]` behavior with array types #35

Open fuhsnn opened 10 months ago

fuhsnn commented 10 months ago

This is a GCC extension; for arrays it reports alignment of the variable instead of the element type

#include <stdio.h>
int main(int argc, char** argv) {
    char _Alignas(1024) arr1[11];
    char _Alignas(1024) arr2[argc];
    printf("%d\n", _Alignof arr1); // gcc/clang: 1024 chibicc: 1
    printf("%d\n", _Alignof arr2); // gcc/clang: 1024 chibicc: 8

    printf("%d\n", _Alignof *&arr1); // gcc:1024 clang:1
}