[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gcc
Subject:    layout of __attribute__((packed)) vs. #pragma pack
From:       Geza Herman <geza.herman () gmail ! com>
Date:       2017-07-28 11:51:26
Message-ID: 9e6f636d-99bb-4e07-e69e-2385cc7717a0 () gmail ! com
[Download RAW message or body]

Hi,


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 
either format."


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:

https://gcc.gnu.org/onlinedocs/gcc-7.1.0/gcc/Common-Variable-Attributes.html, 
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 
attribute.


https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html, here the 
text is:

"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?


Thanks,

Geza

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic