Q:

Generate the item values of a constant array of integer logarithms

I cannot seem to understand this piece of code written in c++:
static const char LogTable256[256] = 
{
 #define LT(n) n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n
 -1, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,
 LT(4), LT(5), LT(5), LT(6), LT(6), LT(6), LT(6),
 LT(7), LT(7), LT(7), LT(7), LT(7), LT(7), LT(7), LT(7)
};

how can I generate the same array using loops? 

A:

#define lines can appear anywhere in your code as long their usage follow them. Since they are preprocessor directives, there is no difference between:
static const char LogTable256[256] = 
{
 #define LT(n) n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n
 -1, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,
 LT(4), LT(5), LT(5), LT(6), LT(6), LT(6), LT(6),
 LT(7), LT(7), LT(7), LT(7), LT(7), LT(7), LT(7), LT(7)
};

and
#define LT(n) n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n

static const char LogTable256[256] = 
{
 -1, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,
 LT(4), LT(5), LT(5), LT(6), LT(6), LT(6), LT(6),
 LT(7), LT(7), LT(7), LT(7), LT(7), LT(7), LT(7), LT(7)
};

If the second one makes sense to you, then rest assured that the first is just as good as far as the compiler and behavior of the program is concerned. The first one could mislead human readers to think that the macro is defined in the scope of the declaration of the variable, which is not true.

