From: Jan Engelhardt <[EMAIL PROTECTED]>
Date: Sun, 3 Jun 2007 12:26:45 +0200 (MEST)

> 
> On Jun 3 2007 12:14, Bernhard R. Link wrote:
> >
> >* David Miller <[EMAIL PROTECTED]> [070602 22:09]:
> >> Types must be aligned on their natural size, and GCC can assume
> >> this everywhere you reference such types unless you use the
> >> "packed" GCC attribute.
> >
> >And even with packed, the struct itself must be naturally aligned
> >(unless itself is in a packed struct, if course).
> 
> It is not a struct actually. It is a bytestream that is reinterpreted
> as an integer, that is, for example (it does not really need to be
> skb_network_header),
> 
> unsigned char *p = skb_network_header(skb);
> uint32_t value   = *(uint32_t *)(p[9]);
> 
> I suppose this won't work, so one would have to...
> 
> uint32_t value = (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3];

We have a way to handle this in the kernel, it's called
get_unaligned() and it only emits special unaligned handling on the
platforms that require it:

        value = get_unaligned((u32 *)(p + 9));

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

Reply via email to