lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-users] Re: [lwip] Packed structures


From: Adam Dunkels
Subject: [lwip-users] Re: [lwip] Packed structures
Date: Wed, 08 Jan 2003 23:46:16 -0000

Hi!

On Sunday 30 December 2001 12.02, you wrote:
> Which structs need to be packed? I think there aren't many, only the
> headers of the packets.

I guess this depends on the compiler, but in my experience it is only the 
arp_hdr that needs to be packet. The other headers are aligned in such a way 
that 16-bit word accesses are on a 16-bit word boundary, 32-bit accesses are 
on a 32-bit boundary, etc. I guess the protocol designers had this in mind 
when they designed the header layouts. 

When it comes to the best way to pack the structure, I would think that 
something along the lines of a PACK_STRUCT macro and a PACK_STRUCT_FIELD 
macro would be the way to go. The actual #definition of the macro could be 
put in the arch/cc.h file and the structs that needs packing could be defined 
as:

PACK_STRUCT(
struct a_struct_that_needs_to_be_packed {
   PACK_STRUCT_FIELD(u8_t a);
   PACK_STRUCT_FIELD(u32_t b);
}
)

But it would looks rather cluttred...

/adam
-- 
Adam Dunkels <address@hidden>
http://www.sics.se/~adam
[This message was sent through the lwip discussion list.]




reply via email to

[Prev in Thread] Current Thread [Next in Thread]