Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cornell!rochester!pt.cs.cmu.edu!pt!dld From: dld@F.GP.CS.CMU.EDU (David Detlefs) Newsgroups: comp.lang.c++ Subject: cfront 1.2 bug Message-ID: Date: 12 Apr 89 18:04:56 GMT Organization: CMU CS Department Lines: 54 I think the following is a bug in cfront 1.2. The C++ program ---------------------------------------------------------------------- // This may look like C code, but it is really -*- C++ -*- typedef unsigned int u_int; struct foo { u_int bar : 2; }; #include void main() { foo f; f.bar = 2; cout << "f.bar is " << f.bar << ".\n"; } ---------------------------------------------------------------------- Translates to a ..c file that starts with ---------------------------------------------------------------------- /* <> */ /* < bitfield-bug.c */ char *_new(); char _delete(); char *_vec_new(); char _vec_delete(); typedef unsigned int u_int ; struct foo { /* sizeof foo == 4 */ int _foo_bar :2; }; // ... ---------------------------------------------------------------------- Note the "int" type of the "bar" field, instead of "unsigned int" or "u_int". When I finish compiling and linking this program on a vax, it produces the result f.bar is -2 which is obviously confusing. Using "unsigned" in the original declaration of foo instead of "u_int" is a workaround. Just thought I'd post this so that whoever is working on 2.0 can make sure this bug does not survive in that version. -- Dave Detlefs Any correlation between my employer's opinion Carnegie-Mellon CS and my own is statistical rather than causal, dld@cs.cmu.edu except in those cases where I have helped to form my employer's opinion. (Null disclaimer.) --