BitVecForeach
- Macro
- August 22, 2025
Table of Contents
BitVecForeach
BitVecForeach
Description
Iterate over each bit var
of the given bitvector bv
. This is a convenience macro that iterates forward 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 . |
Success
The body
is executed for each bit of the bitvector bv
from the beginning to the end.
Failure
If the bitvector bv
is NULL or its length is zero, the loop body will not be executed. Any failures within the BitVecForeachIdx
macro (like invalid index access) will result in a fatal log message and program termination.
Usage example (Cross-references)
- In
Foreach.h:139
:
LOG_FATAL( \
"BitVec range overflow: End index {} exceeds bitvector length {}. " \
"If you intended to iterate over all bits, use BitVecForeach instead.", \
_e, \
(bv)->length \
// Test BitVecForeach macro
bool test_bitvec_foreach(void) {
printf("Testing BitVecForeach macro\n");
BitVec bv = BitVecInit();
u64 false_count = 0;
BitVecForeach(&bv, bit, {
if (bit) {
true_count++;
// Test foreach on empty bitvec
BitVecForeach(&bv, bit, {
(void)bit;
count++; // Should not execute
BitVecPush(&bv, true);
count = 0;
BitVecForeach(&bv, bit, {
count++;
result = result && (bit == true);
count = 0;
BitVecForeach(&bv, bit, {
(void)bit;
count++;
int count1 = 0, count2 = 0, count3 = 0, count4 = 0;
BitVecForeach(&bv, bitval, {
(void)bitval;
count1++;
// This should abort due to ValidateBitVec check
int count = 0;
BitVecForeach(&bv, bit, {
(void)bit;
count++;
// Test BitVecForeach macro
bool test_bitvec_foreach(void) {
printf("Testing BitVecForeach macro\n");
BitVec bv = BitVecInit();
u64 false_count = 0;
BitVecForeach(&bv, bit, {
if (bit) {
true_count++;
// Test foreach on empty bitvec
BitVecForeach(&bv, bit, {
(void)bit;
count++; // Should not execute
BitVecPush(&bv, true);
count = 0;
BitVecForeach(&bv, bit, {
count++;
result = result && (bit == true);
count = 0;
BitVecForeach(&bv, bit, {
(void)bit;
count++;
int count1 = 0, count2 = 0, count3 = 0, count4 = 0;
BitVecForeach(&bv, bitval, {
(void)bitval;
count1++;
// This should abort due to ValidateBitVec check
int count = 0;
BitVecForeach(&bv, bit, {
(void)bit;
count++;