BitVecForeachInRangeIdx
- Macro
- August 22, 2025
Table of Contents
BitVecForeachInRangeIdx
BitVecForeachInRangeIdx
Description
Iterate over bits in a specific range of the given bitvector bv
at each index idx
. The variables var
and idx
are declared and defined by this macro. idx
will start from start
and will go till end - 1
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. |
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 access to an invalid index will result in a fatal log message and program termination.
Usage example (Cross-references)
- In
Foreach.h:186
:
///
#define BitVecForeachInRange(bv, var, start, end, body) \
BitVecForeachInRangeIdx((bv), (var), (____iter___), (start), (end), {body})
#ifdef __cplusplus
// Test BitVecForeachInRangeIdx macro
bool test_bitvec_foreach_in_range_idx(void) {
printf("Testing BitVecForeachInRangeIdx macro\n");
BitVec bv = BitVecInit();
bool range_correct = true;
BitVecForeachInRangeIdx(&bv, bit, idx, 1, 4, {
// Should iterate over indices 1, 2, 3
// Values: false, true, false
// Test BitVecForeachInRangeIdx macro
bool test_bitvec_foreach_in_range_idx(void) {
printf("Testing BitVecForeachInRangeIdx macro\n");
BitVec bv = BitVecInit();
bool range_correct = true;
BitVecForeachInRangeIdx(&bv, bit, idx, 1, 4, {
// Should iterate over indices 1, 2, 3
// Values: false, true, false