On Tue, 18 Jan 2022, Bin.Cheng via Gcc-help wrote: > Hi, > With -Waddress-of-packed-member option, GCC gives warning message if > address of packed structure member is taken and assigned to pointer, > like: > struct foo { > char a; > int b; > } __attribute__((packed)); > > int main() > { > struct foo foo; > int *p; > p = &foo.b; // !! > *p = 1234; > return 0; > } > > This is expected, however, I wonder if there is any way to let gcc > know that `p` is a pointer that might be unaligned, so that an > unaligned access instruction is generated if `p` is dereferenced? > IIRC, microsoft compiler has __unaligned keyword extended for pointer > declaration. Sure, just add a new type with non-standard alignment. Instead of 'int *p' you can write e.g. typedef int i32u __attribute__((aligned(1))); i32u *p; Alexander