On 11 August 2017 at 22:58, Samuel Thibault <samuel.thiba...@gnu.org> wrote:
> Programmingkid, on jeu. 10 août 2017 16:44:19 -0400, wrote:
>> While compiling I saw these error messages:
>> slirp/ip6_icmp.c:79:32: warning: taking address of packed member 'ip_src' of
>> class or
>> structure 'ip6' may result in an unaligned pointer value
>> if (IN6_IS_ADDR_MULTICAST(&ip->ip_src) ||
>> slirp/ip_input.c:159:43: warning: taking address of packed member 'ip_link'
>> of class or
>> structure 'ipq' may result in an unaligned pointer value
>> for (l = slirp->ipq.ip_link.next; l != &slirp->ipq.ip_link;
> Well, if the compiler was counting well, it would notice that the
> structure are made so that even with packing, fields always get aligned
> on proper bounds.
The utility of the warning is that it means you get told
about stuff that might break on other architectures. Eg
x86's alignment restrictions are practically nonexistent
but sparc is much more restrictive. It's better to get
warnings on all hosts so these things can be cleaned
up rather than have them only be warnings on the less
commonly used hosts where nobody will notice them.
(GCC ideally ought to warn about this but doesn't:
that's a bug/missing feature in gcc.)
That said, some of these are a bit odd -- comparing
a pointer value should be fine, as should using
a pointer to a packed struct field inside a
function -- it's only when that pointer is cast
to a non-packed-pointer-type (including by passing
it to another function) that the compiler loses the
information that the pointer is potentially unaligned.