This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
problem because of signed bitfield compares
- To: bug-gcc at gnu dot org
- Subject: problem because of signed bitfield compares
- From: Chuck Rossi <chuckr at vmware dot com>
- Date: Tue, 12 Oct 1999 17:05:06 -0700
Problem: In gcc 2.95, problem because of signed bitfield compares.
This code worked correctly in gcc 2.7.2.3
Compiler:
Reading specs from /usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95/specs
gcc version 2.95 19990728 (release)
Machine:
Linux cannes.vmware.com 2.2.5-15smp #1 SMP Mon Apr 19 22:43:28 EDT 1999 i686 unknown
Red Hat Linux release 6.0 (Hedwig)
Kernel 2.2.5-15smp on an i686
Compile:
% gcc -O -o bittest bittest.c
File: bittest.c
********************************** CUT **********************************
#include <stdio.h>
typedef struct Descriptor {
unsigned limit_lo : 16;
unsigned base_lo : 16;
unsigned base_mid : 8;
unsigned limit_hi : 4;
unsigned base_hi : 8;
} Descriptor;
#define LIMIT(_desc) (((_desc).limit_lo<<8))
#define BASE(_desc) (((_desc).base_hi<<24) | ((_desc).base_mid<<16))
void main(void) {
Descriptor desc;
unsigned base,limit,sum;
desc.base_lo = 0x5e8a;
desc.base_hi = 0x7f;
desc.base_mid = 0xfe;
desc.limit_lo = 0x90c3;
desc.limit_hi = 0x3;
base = BASE(desc);
limit = LIMIT(desc);
printf("base=%08x lim=%05x sum=%08x x=%d\n", BASE(desc), LIMIT(desc), BASE(desc)+LIMIT(desc), BASE(desc)+LIMIT(desc)<BASE(desc));
if((BASE(desc) + LIMIT(desc)) < (BASE(desc))) {
printf("bad\n");
}
}
********************************** CUT **********************************
Thanks....
--
Chuck Rossi
VMware, Inc.
650-475-5221