https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93910
stephane.goujet at wanadoo dot fr changed: What |Removed |Added ---------------------------------------------------------------------------- Status|RESOLVED |UNCONFIRMED Resolution|INVALID |--- --- Comment #9 from stephane.goujet at wanadoo dot fr --- Re-opening until some action is decided or conclusion is reached on the following items: 1. There is a documentation problem for the attribute 'packed'. The fact that this attribute modifies not only the 'internal' padding but also the 'external' alignment should be clearly stated. It may be obvious to you, but for the reader it is not, and this behaviour is not particularly expected/natural. I made a few experiments with clang (8) and Microsoft compiler (2019), they do not seem to change the external alignment, they align packed structs like regular structs. GCC behaviour is a bit of an outlier, hence the need for an explicit specification. 2. There are inconsistencies in the Warning: 2.a A packed struct declared with a "#pragma pack" does not trigger the warning (a similar thing has apparently been reported in bug <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90452> 9 months ago but was ignored), despite having the same apparent effect on the structure 'external' alignment. 2.b A packed struct inside an array does not trigger the warning. I could add a: 1.b #pragma pack is said to mimic MSVC behaviour, however by modifying 'external' alignment, it behaves a bit differently than my (only) experiment with MSVC. Example code: --------------------------------- # 1 "inconsistent.c" # 1 "<built-in>" # 1 "<command-line>" # 31 "<command-line>" # 1 "/usr/include/stdc-predef.h" 1 3 4 # 32 "<command-line>" 2 # 1 "inconsistent.c" struct __attribute__((packed)) S { char a; int b; }; #pragma pack(push, 1) struct S2 { char a; int b; }; #pragma pack(pop) int main(void) { struct S s; struct S a[10]; int *ps = (int *) &s; int *pa0 = (int *) &a[0]; int *pa1 = (int *) &a[1]; struct S2 s2; struct S2 a2[10]; int *ps2 = (int *) &s2; int *pa20 = (int *) &a2[0]; int *pa21 = (int *) &a2[1]; return 0; } ------------------------- Result (it only warns on the case we saw previously, not on the others): ------------------------- ~/test/c/gcc9packed $LC_ALL=C gcc -Wextra inconsistent.c -o inconsistent_gcc -save-temps inconsistent.c: In function 'main': inconsistent.c:17:2: warning: converting a packed 'struct S' pointer (alignment 1) to a 'int' pointer (alignment 4) may result in an unaligned pointer value [-Waddress-of-packed-member] 17 | int *ps = (int *) &s; | ^~~ inconsistent.c:1:32: note: defined here 1 | struct __attribute__((packed)) S { | ^ ------------------------- (PS: thanks for having dealt with the small translation mistake.)