public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/17173] New: layout of bitfields with larger-than-int base type
@ 2004-08-24 20:01 terra at gnome dot org
  2004-08-24 20:14 ` [Bug c/17173] " terra at gnome dot org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: terra at gnome dot org @ 2004-08-24 20:01 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2004-08-31 11:12 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-08-24 20:01 [Bug c/17173] New: layout of bitfields with larger-than-int base type terra at gnome dot org
2004-08-24 20:14 ` [Bug c/17173] " terra at gnome dot org
2004-08-24 20:28 ` pinskia at gcc dot gnu dot org
2004-08-24 23:34 ` jsm at polyomino dot org dot uk
2004-08-27  6:27 ` pinskia at gcc dot gnu dot org
2004-08-31 11:12 ` ebotcazou at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).