- Notifications
You must be signed in to change notification settings - Fork 15.3k
Description
In C++17 standard say,
An alignment-specifier may be applied to a variable or to a class data member, but it shall not be applied to a
bit-field, a function parameter, or an exception-declaration (18.3).
The alignment-specifier is language realm, and __attribute__((aligned)) is gcc extension.
https://discourse.llvm.org/t/whats-the-difference-between-attribute-aligned-x-and-c-11-alignas/62391
This post mention it, but not enough.
So, I want to know can we apply __attribute__((aligned)) to c++'s bit field? Is a undefined behavior? Or like that post, what is diff between alignas and __attribute__((aligned)) .
What lead to this problem is follow code:
#include <stdlib.h> #include <stdio.h> #include <string.h> #include <stdarg.h> extern void *memset (void *__s, int __c, size_t __n); struct S94 { long long int __attribute__((aligned)): 0; }; struct S94 s94; void check94va(int z, ...) { va_list ap; va_start(ap, z); struct S94 arg1 = va_arg(ap, struct S94); long long int tmp = va_arg(ap, long long); //printf("result = %lld\n", tmp); if (tmp != 2LL) { printf("Fails!!!!\n"); } va_end(ap); } int main(void) { memset(&s94, '\0', sizeof(s94)); //printf("sizeof(s94) = %ld\n", sizeof(s94)); check94va(1, s94, 2LL); return 0; } failed in aarch64 as C++ code compiled use clang++. If not apply __attribute__((aligned)) for long long int, it work.