www.digitalmars.com         C & C++   DMDScript  

D - [BUG] Bit assignment and bit array problems

Using DMD 0.78, Windows 98SE.

Two bugs can be seen here:

1. An assignment expression on a bit always seems to evaluate to false, 
making chain assignments impossible.

2. In a foreach statement, a bit array is treated as a byte array, with 
as many bytes as there really are bits and padded with garbage.

Consequently, the program below gives the output

0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0
0
0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 1 1 0
8 33 196 0 0 0 0 0 227 40 64 0 1 0 0 0 80 133 9 134 248 253 100 0 196

(where 227 et seq vary from one run to the next)

instead of the expected

1 1 0 0 0 1 1 0 0 0 1 1 0 0 0 1 1 0 0 0 1 1 0 0 0
1
1 1 0 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 0 1 1 1 1 0
1 1 0 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 0 1 1 1 1 0

Casting the bits to ints in the printf statements has no effect.

Stewart.

----------
int main() {
         bit[25] data;

         for (int i = 0; i < 25; i += 5) {
                 data[i+0] = data[i+1] = true;
         }

         for (int i = 0; i < 25; i++) {
                 printf("%d ", data[i]);
         }

         printf("\n%d\n", data[22] = true);

         for (int i = 0; i < 25; i += 5) {
                 data[i+1] = data[i+3] = true;
         }

         for (int i = 0; i < 25; i++) {
                 printf("%d ", data[i]);
         }

         printf("\n");

         foreach (bit b; data) {
                 printf("%d ", b);
         }

         return 0;
}

-- 
My e-mail is valid but not my primary mailbox, aside from its being the 
unfortunate victim of intensive mail-bombing at the moment.  Please keep 
replies on the 'group where everyone may benefit.
Jan 15 2004