www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - BitArray crash

reply "Danny" <danny.milo+a gmail.com> writes:
Hi,

I'm trying to use BitArray instead of rolling my own. But how 
does one use it?

I tried:

import std.bitmanip : BitArray;

int main() {
	BitArray b;
	b[2] = true;
	return 0;
}

$ gdc l.d
$ gdb a.out
(gdb) r
Program received signal SIGSEGV, Segmentation fault.
0x0000000000438f88 in std.bitmanip.BitArray.opIndexAssign() 
(this=..., b=true,
     i=2) at ../../../../src/libphobos/src/std/bitmanip.d:604

Huh?

(gdc-4.8 (Ubuntu 4.8.2-19ubuntu1) 4.8.2)

I think I have to set "length" first. At least an example at the 
docs of bitsSet() halfway down the page does it...
Jan 30 2015
parent "Nicholas Wilson" <iamthewilsonator hotmail.com> writes:
 I think I have to set "length" first.
Yes. Declaring BitArray b; is like declaring int[] a; // ={.length = 0, . ptr = null} you get the segfault for invalid dereference.
Jan 30 2015