BitVecForeachReverse

Table of Contents

BitVecForeachReverse

Description

Iterate over each bit var of the given bitvector bv in reverse order. This is a convenience macro that iterates backward using an internally managed index. The variable var is declared and defined by this macro.

Parameters

NameDirectionDescription
bvin,outBitvector to iterate over.
varinName of the variable to be used which will contain the value of the current bit during iteration. The type of var will be bool.

Success

The body is executed for each bit of the bitvector bv from the end to the beginning.

Failure

If the bitvector bv is NULL or its length is zero, the loop body will not be executed. Any failures within the BitVecForeachReverseIdx macro (like invalid index access) will result in a fatal log message and program termination.

Usage example (Cross-references)

    // Test BitVecForeachReverse macro
    bool test_bitvec_foreach_reverse(void) {
    printf("Testing BitVecForeachReverse macro\n");
    
    BitVec bv = BitVecInit();
    bool first_is_true = false; // Should be the last bit (true)
    
    BitVecForeachReverse(&bv, bit, {
    if (count == 0) {
    first_is_true = (bit == true);
    
    // Test reverse foreach on empty bitvec
    BitVecForeachReverse(&bv, bit, {
    (void)bit;
    result = false; // Should not execute
    BitVecPush(&bv, true);
    int count = 0;
    BitVecForeachReverse(&bv, bit, {
    count++;
    result = result && (bit == true);
    bool expected_sequence[] = {true, false, true}; // Reverse order
    int  seq_idx             = 0;
    BitVecForeachReverse(&bv, bit, {
    result = result && (bit == expected_sequence[seq_idx]);
    seq_idx++;
    count2++;
    });
    BitVecForeachReverse(&bv, bitval, {
    (void)bitval;
    count3++;
    // Test BitVecForeachReverse macro
    bool test_bitvec_foreach_reverse(void) {
    printf("Testing BitVecForeachReverse macro\n");
    
    BitVec bv = BitVecInit();
    bool first_is_true = false; // Should be the last bit (true)
    
    BitVecForeachReverse(&bv, bit, {
    if (count == 0) {
    first_is_true = (bit == true);
    
    // Test reverse foreach on empty bitvec
    BitVecForeachReverse(&bv, bit, {
    (void)bit;
    result = false; // Should not execute
    BitVecPush(&bv, true);
    int count = 0;
    BitVecForeachReverse(&bv, bit, {
    count++;
    result = result && (bit == true);
    bool expected_sequence[] = {true, false, true}; // Reverse order
    int  seq_idx             = 0;
    BitVecForeachReverse(&bv, bit, {
    result = result && (bit == expected_sequence[seq_idx]);
    seq_idx++;
    count2++;
    });
    BitVecForeachReverse(&bv, bitval, {
    (void)bitval;
    count3++;

Share :