Slimelite BBS

Bug in BC++ 5.0

Back to EMULATE

From Sean Palmer · 1996-04-10 22:55 · #73584 in EMULATE

 > Borland 5 has a bug with Anonymous structs-- putting an
 > anonymous struct inside a union causes the struct to be
 > erroneously treated as a union as well.  Even without being
 > in a union, bit-fields inside an anonymous struct
 > are not honored.
 >
 > I told them about it and their tech rep laughed at me and
 > at Microsoft.
 >
 > Hope he had a good laugh. I'm not impressed.

JP>     I guess I missed something.  What specifically did the tech rep la
JP>and how does Microsoft come into your story?

JP>     In any case, could you please provide some sample code so that we 
JP>determine if the problem is real, and if so, if we can find a workaroun
JP>less impressed with others not being impressed than I am with finding 
JP>solutions to problems.

The problem is real. The workaround is to not use anonymous structs inside 
of unions. The bug-fix waiting list for 5.0 is really long...

Here is the code.

#pragma anon_struct on

struct broke {
  union {
    struct {
      unsigned char b:5;  //these bitfields are broken
      unsigned char c:3;
      long k;
      };
    unsigned char r;
    } n;
  };

void test_broke() {
  broke z;
  z.n.r=0;
  z.n.b=1;
  z.n.c=2;
  z.n.k=3;
  }


struct works {
  union {
    struct {
      unsigned char b:5;  //these bitfields work
      unsigned char c:3;
      long k;
      } a;
    unsigned char r;
    } n;
  };

void test_works() {
  works z;
  z.n.r=0;
  z.n.a.b=1;
  z.n.a.c=2;
  z.n.a.k=3;
  }


Look at the generated code by doing a right-click, then select Special | 
C++ to Assembler and then edit the .ASM file produced.

Project options don't seem to matter a whole lot.

---
 * WR 1.32 # 380 * Man's best possession is a sympathetic wife.
 * Origin: deltaComm Online (919) 481-9399 (1:151/107)