[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [lwip-users] a question about alignment
From: |
K.J. Mansley |
Subject: |
Re: [lwip-users] a question about alignment |
Date: |
03 Nov 2004 09:20:49 +0000 |
On Wed, 2004-11-03 at 07:42, jack W wrote:
> hi everyone
>
>
> i am reading the lwip source codes , i happend a question about structure
> alignments .
>
> in the codes it says : there are four macros #PACK_STRUCT_BEGIN
> #PACK_STRUCT_FIELD
> #PACK_STRUCT_STRUCT and #PACK_STRUCT_END
>
> if i define a structure named xyz following :
>
> #PACK_STRUCT_BEGIN
> struct xyz{
> int xxx
>
> }
> #PACK_STRUCT_END
>
> IF i should write the "#PACK_STRUCT_FIELD" in the front of variable "int xxx"
> or not ?
>
Yes. However, note that you only need to pack structures if they will
be mapped onto data that is sent or received via the network (e.g.
packet headers). If it's just for internal state, there is no need to
pack (and in fact packing is in most cases/architectures a precautionary
measure).
Also, if it does need to be packed, you should probably be using a type
such as "u32_t" rather than "int" in the above example, as you don't
know what size the int will be on different architectures.
Hope that helps,
Kieran