On Saturday 08 November 2008, Nicolas Pitre wrote:
> The ARM processor traditionally cannot access misaligned short and int 
> values in memory.  By using the packed attribute you tell the compiler 
> that the structure should not have inserted padding to align its 
> members, and that accesses are to be performed wth byte accesses and the 
> value reconstructed that way.

... but then when you pass "&misaligned_ptr->member" to some other
function, that other function generally won't know it needs to use
byte access.  So, be careful.  The "packed" struct attribute isn't
a panacea.

General Linux kernel policy is to use <asm/unaligned.h> accessors,
but obviously "packed" has advantages when you've got to pull
structures out of protocol buffers.  The userspace headers don't
seem to support such accessors though.

Also, the network stack is known for making assumptions about its
data being properly aligned.  See how NET_IP_ALIGN is used inside
the kernel; you might be happier aligning your RX buffers before
reading data into them from the kernel.

- Dave

--
To unsubscribe from this list: send the line "unsubscribe linux-embedded" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to