BitVecForeachReverse
- Macro
- October 8, 2025
Table of Contents
BitVecForeachReverse
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
Name | Direction | Description |
---|---|---|
bv | in,out | Bitvector to iterate over. |
var | in | Name of the variable to be used which will contain the value of the current bit during iteration. The type of var will be bool . |
Usage example (Cross-references)
// Test BitVecForeachReverse macro
bool test_bitvec_foreach_reverse(void) {
WriteFmt("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) {
WriteFmt("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++;