Update
This commit is contained in:
parent
3de5192a17
commit
b6b9958383
10 changed files with 158 additions and 6 deletions
|
@ -85,4 +85,10 @@ if (x)
|
|||
|
||||
As in typical code this works the same and is faster. However if the variable *x* is part of shared memory and can be changed by an outside process during the execution of the loop, this optimization can no longer be done as it results in different behavior. This can be prevented with the `volatile` keyword which tells the compiler to not perform such optimizations.
|
||||
|
||||
Of course this applies to other languages as well, but C is especially known for having a lot of undefined behavior, so be careful.
|
||||
Of course this applies to other languages as well, but C is especially known for having a lot of undefined behavior, so be careful.
|
||||
|
||||
## Other
|
||||
|
||||
Watch out for **operator precedence**! Bracket expressions if unsure, or just to increase readability for others.
|
||||
|
||||
Also watch out for this one: `!=` is not `=!` :) I.e. `if (x != 4)` and `if (x =! 4)` are two different things, the first means *not equal* and is usually what you want, the latter is two operations, `=` and `!`, the tricky thing is it also compiles and may work as expected in some cases but fail in others, leading to a very nasty bug.
|
Loading…
Add table
Add a link
Reference in a new issue