[Bug c/17173] New: layout of bitfields with larger-than-int base type

terra at gnome dot org gcc-bugzilla@gcc.gnu.org
Tue Aug 24 20:01:00 GMT 2004


The program below prints 8, 4 for me.

>From http://www.open-std.org/jtc1/sc22/wg14/www/docs/n869/n869.txt.gz
we have...

[#10] A bit-field declaration with no declarator, but only a
       colon and a width, indicates an unnamed bit-field.96)  As  a
       special case, a bit-field structure member with a width of 0
       indicates that no further bit-field is to be packed into the
       unit in which the previous bit-field, if any, was placed.

My reading of this is that Foo1 and Foo2 should be laid out identically
and that the claimed type for ":0" fields is irrelevant.  The type of
the *previous* unit is what matters.

We obviously have a least one leg into implementation-defined territory.




-----------------------------------------------------------------------------

#include <stddef.h>
#include <stdio.h>

typedef int s;

int
main (int argc, char **argv)
{
  struct Foo1 {
    int : 1;
    unsigned long long int : 0;
    int z;
  };

  struct Foo2 {
    int : 1;
    int : 0;
    int z;
  };


  printf ("%d\n", offsetof (struct Foo1, z));
  printf ("%d\n", offsetof (struct Foo2, z));

  return 0; 
}

-- 
           Summary: layout of bitfields with larger-than-int base type
           Product: gcc
           Version: 3.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: terra at gnome dot org
                CC: gcc-bugs at gcc dot gnu dot org
  GCC host triplet: sparc-sun-solaris2.8


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17173



More information about the Gcc-bugs mailing list