lwip-users
[Top][All Lists]
Advanced

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

Re: [lwip-users] Struct packing/alignment problems


From: Leon Woestenberg
Subject: Re: [lwip-users] Struct packing/alignment problems
Date: Mon, 26 Apr 2004 18:21:06 +0200
User-agent: Mozilla Thunderbird 0.5 (Windows/20040207)

Hello all,

On Mon, 2004-04-26 at 15:02, address@hidden wrote:


Once the structs are nicely aligned I can see no reason to use struct packing compiler directives.
But of course, we can't be 100% certain until it have been tested.


It's not just the initial alignment that is important, it's also the
layout within the structure.  Without a packed struct (I think - could
be wrong on this!) you can't guarantee that the compiler won't insert
gaps (or reorder the elements) within the struct.  Normally this isn't a
problem as the program is self-consistent, but when you try to access a
network packet using a struct you would clearly be in all sorts of
problems if there were gaps in the struct that aren't in the packet.

Exactly what I was thinking of...

and then I wondered if we can test for wrongly layed out header structs
by using compile-time or run-time assertions that do a sizeof(struct some_header) check against its intentional size, i.e.:

LWIP_ASSERT(sizeof(struct proto_header) == PROTO_HEADER_SIZE);

Regards,

Leon.






reply via email to

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