I was reading the C-FAQ question no: 20.8 which basically deals with bit arrays:
http://c-faq.com/misc/bitsets.html
One of the macros defined looks something like:
#define BITNSLOTS(nb) ((nb + CHAR_BIT - 1) / CHAR_BIT)
Is this macro meant to calculate the num of elements(or slots) in the char array (each slot = 8 bits) ? I am not sure what this macro is doing, in particular what the purpose of “+CHAR_BIT -1/CHAR_BIT” is. Any clues will be appreciated!
Yes, it calculates how many
chars are needed to hold the bits. The addition stuff is to make it round up.