https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93910

--- Comment #2 from Mikael Pettersson <mikpelinux at gmail dot com> ---
(In reply to stephane.goujet from comment #0)
> test2.c: In function 'main':
> test2.c:9:5: 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]
>     9 |     int *pi = (int *) &s;
>       |     ^~~
> test2.c:2:37: note: defined here
>     2 | struct __attribute__ ((__packed__)) S {

IMO the warning is correct.  Simply _creating_ a misaligned pointer is
undefined behaviour, and there are machines where it cannot be done without
losing precision.  void* / char* is the only pointer type that can point to any
object.

Reply via email to