This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: struct and members addresses


Martin York wrote: 

> Just to throw a spanner in the works!
> Assuming C only
>
> What happens if there are more members of the structure.
> Is the compiler allowed to reorder the members of the structure for
> efficiency in memory layout?

No. C99 6.2.5.20 second bullet - "sequentially allocated":

    A /structure type/ describes a sequentially allocated nonempty set
    of member objects (and, in certain circumstances, an incomplete
    array), each of which has an optionally specified name and
    possibly distinct type.

Minor exception for adjacent bit-fields combined into a single unit; 6.2.7.1
bullets 8 and 10:

    A member of a structure or union may have any object type other
    than a variably modified type. In addition, a member may be
    declared to consist of a specified number of bits (including a
    sign bit, if any). Such a member is called a /bit-field/; its
    width is preceded by a colon.

    An implementation may allocate any addressable storage unit large
    enough to hold a bit-field. If enough space remains, a bit-field
    that immediately follows another bit-field in a structure shall be
    packed into adjacent bits of the same unit. ... The order of
    allocation of bit-fields with a unit (high-order to low-order or
    low-order to high-order) is implementation defined. The alignment
    of the addressable storage unit is unspecified.



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]