This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/12176] New: Incorrect size for unions with very large bitfields
- From: "austern at apple dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 5 Sep 2003 04:53:01 -0000
- Subject: [Bug c++/12176] New: Incorrect size for unions with very large bitfields
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
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.