Oracle® Solaris Studio 12.4: C++ User's Guide

Exit Print View

Updated: March 2015
 
 

4.11.2 __packed__ Attribute Details


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. When attached to an enum definition, __packed__ indicates that the smallest integral type should be used.

Specifying this attribute for struct and union types is equivalent to specifying the packed attribute on each of the structure or union members.

In the following example, struct my_packed_struct's members are packed closely together but the internal layout of its s member is not packed. To do that, struct my_unpacked_struct would also need to be packed.

struct my_unpacked_struct
{
   char c;
   int i;
;
              
struct __attribute__ ((__packed__)) my_packed_struct
{
   char c;
   int  i;
   struct my_unpacked_struct s;
};

You may only specify this attribute on the definition of an enum, struct, or union, and not on a typedef that does not also define the enumerated type, structure, or union.