This is the mail archive of the
mailing list for the GCC project.
layout of __attribute__((packed)) vs. #pragma pack
- From: Geza Herman <geza dot herman at gmail dot com>
- To: "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>
- Date: Fri, 28 Jul 2017 13:51:26 +0200
- Subject: layout of __attribute__((packed)) vs. #pragma pack
- Authentication-results: sourceware.org; auth=none
There's an option in GCC "-mms-bitfields". The doc about it begins with:
"If packed is used on a structure, or if bit-fields are used, it may be
that the Microsoft ABI lays out the structure differently than the way
GCC normally does. Particularly when moving packed data between
functions compiled with GCC and the native Microsoft compiler (either
via function call or as data in a file), it may be necessary to access
I'm particularly interested in packed structs, bit-fields are not a
concern now. Does this doc mean, that a packed struct layout may differ
between GCC and MSVC? The doc doesn't give an example of this, it just
talks about bit-fields. If the packed layout can differ, in which way
does it? Previously I thought that both compilers put members into the
struct without any padding, so the layout must match.
Plus, __attribute__((packed)) documentation have changed:
here the text is:
The packed attribute specifies that a variable or structure field should
have the smallest possible alignment—one byte for a variable, and one
bit for a field, unless you specify a larger value with the aligned
https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html, here the
"This attribute, attached to struct or union type definition, specifies
that each member (other than zero-width bit-fields) of the structure or
union is placed to minimize the memory required"
What does "minimize" mean here? Does it give the same guarantees as the
previous definition? Could it mean that there's still padding in the struct?