r/C_Programming • • Jul 07 '26

If statement checking a bool array?

Hi,

I need a custom sized bit vector so uint8_t won't suffice so the idea was to just initiate a bool array with size so then say i want to compare it. Ex**. the bool array is 6 bits and tried with `if (bool_var = 011001) { // do something}`, i suspect it comes just compares to an int given it compiles and wont run. Any idea on how to make it work?**

0 Upvotes

53 comments sorted by

View all comments

Show parent comment

1

u/Vollink Jul 08 '26
$ make bool-4
gcc -Wall -O2 bool-4.c -o bool-4
$ cat bool-4.c
#include <stdio.h>
#include <stdint.h>

struct state {
    unsigned char a : 1;
    unsigned char b : 1;
    unsigned char c : 1;
    unsigned char d : 1;
    unsigned char e : 1;
    unsigned char f : 1;
};

int main()
{
    printf("size of struct test: %lu\n", sizeof(struct state));

    return 0;
}

$ ./bool-4
size of struct test: 1
$