I agree with you on some counts, but not on others.
unsigned int countBits (unsigned int x)
{
int i;
int shift; // number of positions to shift to the right
static unsigned int mask[] = {
0x55555555,
0x33333333,
0x0F0F0F0F,
0x00FF00FF,
0x0000FFFF};
for (i = 0, shift = 1; i < 5; i++, shift *= 2)
x = (x & mask[i]) + ((x >> shift) & mask[i]);
return x;
}
Where to put the first '{' depends on your development environment, as some hide the line where the bracket is, and some don't (when you hide a function or loop). Array initialization format is a tricky one, as the spacing is very dependent on how you are trying to visualize the data, but I would agree that all (leftmost) elements should be aligned to the same margin. I find the blank line between array and other declarations puzzling for both examples. I prefer to leave blank lines between code of the same indent (outside of declarations and initializations). Commenting using '//' allows you to comment out blocks of code on both sides of your line comment, so I'm with you there.P.S. I do not like Hacker News' paragraph formatting