From: Jan Engelhardt <jengelh@xxxxxxxxxx> Date: Sun, 1 Nov 2009 14:41:21 +0100 (CET) > +static inline uint32_t deref_get_32(const void *ptr) > +{ > + uint32_t ret; > + memcpy(&ret, ptr, sizeof(ret)); > + return ret; > +} > > Is what I use in one project; however, trying to minimize the > unalignedness - iptables is a "perfect" example, and netlink > may do the same tho I am not sure - seems to be the best > approach in serialized streams. This will not work all the time. If GCC can see at the inlining point that 'ptr' is of a type that should be properly aligned it can inline the memcpy and still emit the very unaligned load or store that you're trying to avoid. Using a void pointer doesn't create a sort of "barrier" for typing visibility like you think it does. So I would argue against using this construct, because it only gives you a false sense of security. -- To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html