www.digitalmars.com         C & C++   DMDScript  

c++.beta - [bug] dmc.8.48.3 bit fields for 64-bit integer

reply Nic Tiger <g_tiger progtech.ru> writes:
Code below produces incorrect output (seems that code generator makes 
invalid code, since nothing is changed when compiling with -o-all):
   a.pos = A;
   b.pos = 1234567890A;
But clearly, these values should be identical; Due to this bug I can't 
use bitfields for int64 in structure.

Nic Tiger.


dmc int64_bug.cpp
----------------------
#include <stdio.h>
#include <stdint.h>

struct A {
   uint64_t pos: 36;
};
struct B {
   uint64_t pos;
};

int main() {
   A a;
   B b;
   a.pos = 0x1234567890A;
   b.pos = 0x1234567890A;
   printf ( "a.pos=%llX\n", a.pos );
   printf ( "b.pos=%llX\n", b.pos );

   return 0;
}
Apr 14 2006
parent Nic Tiger <g_tiger progtech.ru> writes:
Nic Tiger wrote:
 Code below produces incorrect output (seems that code generator makes 
 invalid code, since nothing is changed when compiling with -o-all):
   a.pos = A;
   b.pos = 1234567890A;
 But clearly, these values should be identical; Due to this bug I can't 
 use bitfields for int64 in structure.

ugh.... just came across "9.6-1 Bit Fields" section in DMC C++ language implementation / Implementation-defined Behavior. so, bit fields larger than 32 bit (word size) are not allowed. though, it would be nice if compiler emitted error about that... Nic Tiger.
Apr 14 2006