I study lib RF24NETWORK of maniacbug , and I don't understand this code
void RF24Network::setup_address(void)
{
// First, establish the node_mask
uint16_t node_mask_check = 0xFFFF; while ( node_address & node_mask_check )
node_mask_check <<= 3;
node_mask = ~ node_mask_check;
// parent mask is the next level down
uint16_t parent_mask = node_mask >> 3;
// parent node is the part IN the mask
parent_node = node_address & parent_mask;
// parent pipe is the part OUT of the mask
uint16_t i = node_address;
uint16_t m = parent_mask;
while (m)
{
i >>= 3;
m >>= 3;
}
parent_pipe = i;
All whitespace is equivalent to a single whitespace character.
A tab, a line break, a string of spaces, are all reduced to a single space, during the first pass of the compiler.
Statements are delimited by a semicolon. statement;
A compound statement is one or more statements delimited by braces, better known as a code block
{ statement; statement; }
A compound statement is syntactically equivalent to a statement.
Anywhere you can use a statement, you can use a compound statement.
'while' is a conditional loop with the syntax
while(condition) statement;
Following the rules above
while (true) doSomething();
//is the same as...
while (true)
doSomething();
//is the same as
while (true) { doSomething(); }
//is the same as...
while(true)
{
doSomething();
}
//is the same as
while(true) {
doSomething();
}
Because the compiler only insists the syntax is correct,
it is very important to adopt a consistent formatting style,
to maintain readability of the source.
Personally I favour the last example,
as lines of code always end in a semicolon or a brace character.