not understanding the array declaration along with macro

priyaranjan

Right off the assembly line
hi
here is the code , can any one plzzz explain the below code.

Code:
static const unsigned char BitsSetTable256[256] = 
{
#   define B2(n) n,     n+1,     n+1,     n+2
#   define B4(n) B2(n), B2(n+1), B2(n+1), B2(n+2)
#   define B6(n) B4(n), B4(n+1), B4(n+1), B4(n+2)
    B6(0), B6(1), B6(1), B6(2)
};
 

nims11

BIOS Terminator
hmm, how to explain...
see,
for first element B6(0)
B6(0)=B4(0), B4(1), B4(1), B4(2)=B2(0), B2(1), B2(1), B2(2),........
=0, 1, 1, 2, 1, 2, 2, 3,.........

similarly for B6(1), B6(1) and B6(2)
so all of it comes down to
static const unsigned char BitsSetTable256[256] = { 0, 1, 1, 2, 1, 2, 2, 3,........};
which is a way to initialize an array.
 
Top Bottom