[cfe-dev] clang allow the _Alignof operator being applied to a function type?

zhangxp at cn.fujitsu.com zhangxp at cn.fujitsu.com
Tue Jul 15 19:06:35 PDT 2014


Hi, all!

C11 6.5.3.4/p1 says:
    "The _Alignof operator shall not be applied to a function type or an incomplete type."

But I compiled the following code with clang-3.4 and gcc-4.9 on linux (x86_64):
----------------------------------------------
extern int printf(const char* fmt, ...);
int main() {
    int a = _Alignof(void(int));
    int b = _Alignof(void);
    // int c = _Alignof(struct S); // error: invalid application of 'alignof' to an incomplete type 'struct S' 
    printf("a == %d, b == %d\n", a, b);
}
----------------------------------------------
Results:
    clang-3.4: a == 4, b == 1
    gcc-4.9  : a == 1, b == 1

Question:
    Why both clang and gcc not report error like "invalid application of 'alignof' to a function/incomplete type 'xxxx'"?

Sandy Zhang





More information about the cfe-dev mailing list