contiki-os/contiki — pull request #455 by adamdunkels (2013-11-22 13:39:04+00:00)
Title: Fix compiler warnings

The Contiki code does not compile very cleanly at the moment as there are several compiler warnings produced. This is not good. We should make sure to have a warning-free build.

This pull request fixes a number of warnings.

The pull requests got a bit of pushback from @oliverschmidt when I inadvertently sent it towards contiki-os a while back because the code uses an idiom we haven't used much in Contiki: it uses the C `if()` statement to conditionally compile code. Like this:

Instead of
`#if FLAG`
`code;`
`#endif /* FLAG */`
it does
`if(FLAG) {`
` code;`
`}`

The foremost benefit of this idiom is that it ensures that all code paths get touched by the compiler, even those that are dropped because of the `FLAG` condition. With optimizing compilers, there will be no dead code so the end result is equivalent. In the context of this particular pull request, the idiom is used because there are a bunch of local variables used in parts of the code that was both conditionally and non-conditionally compiled and it became messy to use `#if/#endif` pairs in the variable declarations.

The drawback of the idiom is that the meaning of the code becomes a bit muddled. It is not evidently clear that the `if()` is used for conditional compilation. And we are relying on the compiler's optimizer to drop the dead code, which cannot 100% rely on will happen. But I think the benefits outweigh the drawbacks in this case.