| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | structure packing |
Quoting Paul Edwards to All:
PE>Can someone tell me what the deal is with structure padding?
PE>Does it apply to structures when they are DEFINED or when they are
PE>USED?
I would assume that the definition is where the padding is taken into
account, otherwise 'twould be possible to have two supposedly identical
but incompatible structs:
#pragma pack(1)
struct cow moo;
#pragma pack(4)
struct cow milk;
Both structs must be identical, so the compiler must make the determination
based on the #pragma pack setting in effect at the time the structure was
defined.
PE>ie if I define a struct fred { char x; int y; }; and then do a #pragma
PE>pack(1) (previously was pack(4)), and then declare a variable x, ie
PE>struct fred x;, does x come out 5 or 8?
Huh.
PE>My experimentation with Watcom says that it is the *structure
PE>definition* not the variable, that gets defined with the appropriate
PE>packing.
PE>I was wondering whether this was universal?
It'd have to be; otherwise the compiler would need to be able to
differentiate between which style of padding was used. That'd be silly.
You can't have two different types of "struct moo".
PE>Is it true that gcc under Linux has no compile-time option to pack
PE>structures, same as EMX for OS/2?
I don't know about gcc in general, but EMX supports the #pragma pack(n)
directive, and defaults to #pragma pack(4).
... Oxymoron: Press Release.
--- FMail/Win32 1.22
* Origin: Power BBS - +61-2-858-4114 - Files/Games/EchoMail/Internet (3:711/953)SEEN-BY: 633/267 270 @PATH: 711/953 410 808 50/99 635/728 633/267 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.