This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/44260] New: Strange behavior on bit fields sructures.
- From: "dennis at conus dot info" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 24 May 2010 13:24:18 -0000
- Subject: [Bug c++/44260] New: Strange behavior on bit fields sructures.
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
If compiled without -O3 option, this code snippet works fine (running
executable will print "i=11223344, bswap=44332211")
If compiled with -O3 option, executable will print "i=11223344,
bswap=00000000".
Checked on 4.4.1 x86 and 4.4.3 x64.
#include <stdio.h>
struct int32_bytes
{
int byte1:8;
int byte2:8;
int byte3:8;
int byte4:8;
};
unsigned int bswap (unsigned int in)
{
struct int32_bytes *tmp_in;
struct int32_bytes *tmp_out;
unsigned int rt;
tmp_in=(struct int32_bytes *)∈
tmp_out=(struct int32_bytes *)&rt;
tmp_out->byte1 = tmp_in->byte4;
tmp_out->byte2 = tmp_in->byte3;
tmp_out->byte3 = tmp_in->byte2;
tmp_out->byte4 = tmp_in->byte1;
return rt;
};
int main()
{
for (int i=0x11223344; i<=0x112233FF; i++)
{
if (i==0x11223344)
printf ("i=%08X, bswap=%08X\n", i, bswap (i));
};
};
--
Summary: Strange behavior on bit fields sructures.
Product: gcc
Version: 4.4.3
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: dennis at conus dot info
GCC build triplet: 4.4.3
GCC host triplet: 4.4.3
GCC target triplet: 4.4.3
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44260