* Re: packed and aligned structures
@ 2001-09-12 13:18 Shaun Jackman
0 siblings, 0 replies; 2+ messages in thread
From: Shaun Jackman @ 2001-09-12 13:18 UTC (permalink / raw)
To: gcc-help
On the matter of exact structure size. I forget to mention I've already tried
specifying -mstructure-size-boundary=8, which had the desired with 2.95.2.
This doesn't seem to work with 3.0.1 though. Is it still a supported option?
Thanks,
Shaun
On September 12, 2001 13:58, you wrote:
> I'm sure this is a common question, and I thought I had it solved in
> 2.95.2, but I've recent upgraded to 3.01 and the problem rears its ugly
> head again. Here's a basic rundown of what I'm looking for.
>
> All my protocol structures must be PACKED (no padding in the structure),
> EXACT SIZE (no padding at the end of the structure, if the structure is 13
> bytes long, sizeof( mystruct) should return 13, not 16), and ALIGNED to a 4
> byte boundary. What combination of attributes and command line switches can
> I use to accomplish this?
>
> --- ALIGNED ---
> In 2.95.2 all my structures always seemed to be on 4 byte
> boundaries regardless of content, however 3.01 put a structure of this form
> typedef struct {
> char pad[2];
> char data[ 1400];
> } mystruct;
> on a 2 byte boundary. Will
> } __attribute__((aligned(4))) mystruct;
> fix this? Is there a command line switch to force this for all structs?
>
> --- EXACT SIZE ---
> typedef struct {
> long src,
> long dst,
> char mbz,
> char prot,
> short len,
> short checksum
> } mystruct;
> sizeof( mystruct) returns 16, how do I make this return 14?
>
> --- PACKED ---
> typedef struct {
> ...
> } __attribute__((packed)) mystruct;
> Will this force all the members of the structure to be packed (ie no
> padding in the structure)?
> typedef struct {
> ...
> } __attribute__((packed, aligned(4))) mystruct;
> Does this construct make sense to force the structure to a 4 byte boundary,
> as well as packing the members?
>
> Many thanks,
> Please cc me as I'm not a member of the list,
> Shaun
^ permalink raw reply [flat|nested] 2+ messages in thread
* packed and aligned structures
@ 2001-09-12 12:58 Shaun Jackman
0 siblings, 0 replies; 2+ messages in thread
From: Shaun Jackman @ 2001-09-12 12:58 UTC (permalink / raw)
To: gcc-help
I'm sure this is a common question, and I thought I had it solved in 2.95.2,
but I've recent upgraded to 3.01 and the problem rears its ugly head again.
Here's a basic rundown of what I'm looking for.
All my protocol structures must be PACKED (no padding in the structure),
EXACT SIZE (no padding at the end of the structure, if the structure is 13
bytes long, sizeof( mystruct) should return 13, not 16), and ALIGNED to a 4
byte boundary. What combination of attributes and command line switches can I
use to accomplish this?
--- ALIGNED ---
In 2.95.2 all my structures always seemed to be on 4 byte
boundaries regardless of content, however 3.01 put a structure of this form
typedef struct {
char pad[2];
char data[ 1400];
} mystruct;
on a 2 byte boundary. Will
} __attribute__((aligned(4))) mystruct;
fix this? Is there a command line switch to force this for all structs?
--- EXACT SIZE ---
typedef struct {
long src,
long dst,
char mbz,
char prot,
short len,
short checksum
} mystruct;
sizeof( mystruct) returns 16, how do I make this return 14?
--- PACKED ---
typedef struct {
...
} __attribute__((packed)) mystruct;
Will this force all the members of the structure to be packed (ie no padding
in the structure)?
typedef struct {
...
} __attribute__((packed, aligned(4))) mystruct;
Does this construct make sense to force the structure to a 4 byte boundary,
as well as packing the members?
Many thanks,
Please cc me as I'm not a member of the list,
Shaun
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2001-09-12 13:18 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-09-12 13:18 packed and aligned structures Shaun Jackman
-- strict thread matches above, loose matches on Subject: below --
2001-09-12 12:58 Shaun Jackman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).