c/9110: Zero-length bitfields cause wider structure when -fpack-struct is specified

etiotto@ca.ibm.com etiotto@ca.ibm.com
Mon Dec 30 16:46:00 GMT 2002


>Number:         9110
>Category:       c
>Synopsis:       Zero-length bitfields cause wider structure when -fpack-struct is specified
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Dec 30 16:46:00 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     Ettore Tiotto
>Release:        gcc-3.2
>Organization:
>Environment:
powerpc-suse-linux
>Description:
When the -fpack-struct command line option is used, a zero-length bitfield 
of type short causes padding to the next 4-byte boundary, and makes the 
structure size greater than the one it has when -fpack-struct is not 
specified.
>How-To-Repeat:
Consider the following structure:

struct A {
        int   a;
        short  :0;
        int   b:15;
};

without -fpack-struct, the structure layout is:

      aaaaaaaa  ........  bbbbbbbb  bbbbbbb.    

the zero-length bit-field of type short caused member b to be mapped at offset 2 
from the beginning of the structure. The structure has size 4 bytes.

With -fpack-struct the structure layout is:

      aaaaaaaa  ........  ........  ........  bbbbbbbb  bbbbbbb. 

Member b is now mapped at offset 4 and the structure occupies 6 bytes.

When -fpack-struct is specified I would expect the structure to occupies 
3 bytes, with no padding between members a and b:

aaaaaaaa  bbbbbbbb  bbbbbbb. 

or alternativelly to have the same layout as without -fpack-struct. 
Whichever layout is choosen, the structure size should not be greater 
than 4 bytes.

Note: with -fpack-struct specified, member b is mapped at offset 4 even when 
      it is a bitfield of type char, int or long. Strange enough when member b
      has long long type and -fpack-struct is specified, b has offset 8.
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the Gcc-prs mailing list