On Thu, 13 Apr 2006 16:16:43 -0700, Curt McDowell wrote:
>Unions are really ugly, and I don't think they're necessary in pbuf.c.  But
>your idea to use an embedded structure is good.  How about the following?
>
>struct {
>  struct pbuf pbuf;
>  u8_t payload[MEM_ALIGN_SIZE(PBUF_POOL_BUFSIZE)];
>} pbuf_pool_memory[PBUF_POOL_SIZE];
>
>The alignment requirement of a structure is the maximum of the alignment
>requirements of any member of the structure.  struct pbuf is intrinsically
>aligned.
A struct pbuf is only guaranteed to be suitably aligned for the three
data types it contains: void*, struct pbuf*, and u16_t. There is no
guarantee that this will result in maximum alignment.


>This alignment is inherited by the outer structure and the payload is
>also suitably aligned.
The payload is only guaranteed to be suitably aligned for a u8_t. Even
if sizeof(struct pbuf) is a multiple of the memory alignment, there is
no guarantee that padding bytes aren't inserted after pbuf, which
would leave payload unaligned.

A union may not be aesthetically pleasing, but it can ensure that a
u8_t array is properly aligned for another data type.
-- 
Derek Guerdon



_______________________________________________
lwip-users mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/lwip-users

Reply via email to