BitVecForeachInRange
- Macro
- August 22, 2025
Table of Contents
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
The body
is executed for each bit of the bitvector bv
from the start
index to the end-1
index.
Failure
If the bitvector bv
is NULL, its length is zero, or the range is invalid, the loop body will not be executed. Any failures within the BitVecForeachInRangeIdx
macro will result in a fatal log message and program termination.
Usage example (Cross-references)
// Test BitVecForeachInRange macro
bool test_bitvec_foreach_in_range(void) {
printf("Testing BitVecForeachInRange macro\n");
BitVec bv = BitVecInit();
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++;
// Test BitVecForeachInRange macro
bool test_bitvec_foreach_in_range(void) {
printf("Testing BitVecForeachInRange macro\n");
BitVec bv = BitVecInit();
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++;