Skip to content
BitVecForeachReverseIdx

BitVecForeachReverseIdx

Description

Iterate over each bit var of given bitvector bv at each index idx into the bitvector. The variables var and idx declared and defined by this macro.

idx will start from bv->length - 1 and will go till 0

Parameters

Name Direction Description
bv in,out Bitvector to iterate over.
var in Name of variable to be used which’ll contain bit value at iterated index idx
idx in Name of variable to be used for iterating over indices.

Success

Loop body runs once per bit in reverse order, with var/idx set each step.

Failure

Loop body never executes when bv is empty; validator aborts on corrupted magic.

Usage example (Cross-references)

Usage examples (Cross-references)
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        WriteFmt("Testing BitVecForeachReverseIdx macro\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
        bool first_bit_is_false = false; // Should be last bit when iterating in reverse
    
        BitVecForeachReverseIdx(&bv, bit, idx) {
            if (count == 0) {
                first_bit_is_false = (bit == false) && (idx == 3);
                count3++;
            }
            BitVecForeachReverseIdx(&bv, bitval, i) {
                (void)bitval;
                count4++;
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        WriteFmt("Testing BitVecForeachReverseIdx macro\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
        bool first_bit_is_false = false; // Should be last bit when iterating in reverse
    
        BitVecForeachReverseIdx(&bv, bit, idx) {
            if (count == 0) {
                first_bit_is_false = (bit == false) && (idx == 3);
                count3++;
            }
            BitVecForeachReverseIdx(&bv, bitval, i) {
                (void)bitval;
                count4++;
    /// TAGS: BitVec, Foreach, Reverse, Iteration
    ///
    #define BitVecForeachReverse(bv, var) BitVecForeachReverseIdx((bv), (var), UNPL(iter))
    
    ///
Last updated on