DIGIT-ARC read-only archive · snapshot: July 23, 2026

not understanding the array declaration along with macro

2 posts · originally from https://geek.digit.in/community/threads/not-understanding-the-array-declaration-along-with-macro.151251/

P
priyaranjan Original post #1
Jan 12, 2012 at 1:54 AM
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
nims11 #2
Jan 16, 2012 at 11:00 PM
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.