Skip to content
BitVecForeachInRange

BitVecForeachInRange

Description

Iterate over bits in a specific range of the given bitvector bv. This is a convenience macro that iterates over a range using an internally managed index. The variable var is declared and defined by this macro.

Parameters

Name Direction Description
bv in,out Bitvector to iterate over.
var in Name of variable to be used which’ll contain bit value of the current bit.
start in Starting index (inclusive).
end in Ending index (exclusive).

Success

Loop body runs once for each bit in [start, end) that lies within bv->length.

Failure

Loop body never executes when the range is empty, inverted, or out of bounds; validator aborts on corrupted magic.

Usage example (Cross-references)

Usage examples (Cross-references)
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        WriteFmt("Testing BitVecForeachInRange macro\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
        u64 false_count = 0;
    
        BitVecForeachInRange(&bv, bit, 1, 3) {
            // Should iterate over indices 1, 2
            // Values: true, true
        // Test range with start == end (should not execute)
        int count = 0;
        BitVecForeachInRange(&bv, bit, 5, 5) {
            (void)bit;
            count++; // Should not execute
        // Test range with single element
        count = 0;
        BitVecForeachInRange(&bv, bit, 3, 4) {
            count++;
            result = result && (bit == false); // 3 % 2 != 0
        // Test range at boundaries
        count = 0;
        BitVecForeachInRange(&bv, bit, 0, 2) {
            (void)bit;
            count++;
        // Test range at the end of bitvector
        count = 0;
        BitVecForeachInRange(&bv, bit, 8, 10) {
            (void)bit;
            count++;
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        WriteFmt("Testing BitVecForeachInRange macro\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
        u64 false_count = 0;
    
        BitVecForeachInRange(&bv, bit, 1, 3) {
            // Should iterate over indices 1, 2
            // Values: true, true
        // Test range with start == end (should not execute)
        int count = 0;
        BitVecForeachInRange(&bv, bit, 5, 5) {
            (void)bit;
            count++; // Should not execute
        // Test range with single element
        count = 0;
        BitVecForeachInRange(&bv, bit, 3, 4) {
            count++;
            result = result && (bit == false); // 3 % 2 != 0
        // Test range at boundaries
        count = 0;
        BitVecForeachInRange(&bv, bit, 0, 2) {
            (void)bit;
            count++;
        // Test range at the end of bitvector
        count = 0;
        BitVecForeachInRange(&bv, bit, 8, 10) {
            (void)bit;
            count++;
Last updated on