This is the mail archive of the gcc-bugs@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]

[Bug c++/12176] New: Incorrect size for unions with very large bitfields


PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

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

           Summary: Incorrect size for unions with very large bitfields
           Product: gcc
           Version: 3.4
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: austern at apple dot com
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu

Consider the following C++ code (it has to be C++, because C imposes limits on bitfield sizes):
extern "C" int printf(const char*,...);

union abcde {
  char foo : 4096;
};

int main()
{
  abcde x;
  printf("%d\n", sizeof(x));
}

When I compile and run this program, I get the result "504".  That makes no sense.  I'm running it 
on a system with 8-bit bytes, so the size of an abcde object should be 512.  Somehow 8 bytes 
have been lost.

Note that this is a problem only with unions, not with structs.

I've seen the same behavior with every version of gcc I've tested, from 2.95 through today's 
mainline, and on both OS X and Linux.


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