BitArray contracts

bearophile bearophileHUGS at lycos.com
Mon Aug 23 19:49:14 PDT 2010


This a part of std.bitmanip.BitArray:


    void init(void[] v, size_t numbits)
    in
    {
        assert(numbits <= v.length * 8);
        assert((v.length & 3) == 0);
    }
    body
    {
        ptr = cast(uint*)v.ptr;
        len = numbits;
    }


But it seems this program works with no errors:

import std.bitmanip: BitArray;
void main() {
    ubyte[4] data;
    BitArray bits;
    bits.init(data, 100);
}


Do you kno why is this assert present?
assert((v.length & 3) == 0);

Isn't this enough?
assert((v.length & 2) == 0);

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list