Re: Packed structs vs. unpacked structs: what's the difference?
- From: "slebetman@xxxxxxxxx" <slebetman@xxxxxxxxx>
- Date: 9 Apr 2006 07:08:15 -0700
Nick Keighley wrote:
pete wrote:
Richard G. Riley wrote:
On 2006-04-09, Daniel Rudy <spamthis@xxxxxxxxxxxx> wrote:
What is the difference between packed and unpacked structs?
The packed keyword
I have no idea on the "standardness" of "packed".
It's not standard C.
...and hence should be avoided if possible. "pragma pack" and their ilk
may slow your program at a slight saving in space and a loss of
portability.
Pragma pack is not often used to save space. Rather it is usually used
as a (non-portable) way to quickly "cast" a byte array (for example a
packet) into a struct. This way you can access data within the packet
directly by simply pointing the struct you want to the first byte of
the packet. This trick is very common in the majority of Unix TCP/IP
stack including Linux & BSD. It is also used in Windows TCP/IP stack
although Microsoft has a different syntax for their version of pragma
pack. But this, of course, is non-standard and is off topic to
comp.lang.c.
.
- References:
- Packed structs vs. unpacked structs: what's the difference?
- From: Daniel Rudy
- Re: Packed structs vs. unpacked structs: what's the difference?
- From: Richard G. Riley
- Re: Packed structs vs. unpacked structs: what's the difference?
- From: pete
- Re: Packed structs vs. unpacked structs: what's the difference?
- From: Nick Keighley
- Packed structs vs. unpacked structs: what's the difference?
- Prev by Date: Re: Packed structs vs. unpacked structs: what's the difference?
- Next by Date: Re: Could a struct with size 44 bytes point always points to a char array with size 2048 bytes?
- Previous by thread: Re: Packed structs vs. unpacked structs: what's the difference?
- Next by thread: Re: Packed structs vs. unpacked structs: what's the difference?
- Index(es):
Relevant Pages
|