Things you probably didn't know about C
Posted: Thu Feb 12, 2009 10:27 pm
Statement: Any single line of code or code enclosed in braces
Expression: Something that resolves to a numeric value (0 for false, nonzero for true)
This is the big one, rest are things you probably did know.
Switch syntax is
switch (expression) statement^ Doesn't matter where case:s are as long as they're in a switch block.
For syntax is
for (expression1; expression2; expression3) statement
All expressions in for are optional
Equivalent to
Since many humans put the most common case first in an if else, some compilers switch them when they compile in order to save an assembly (don't)JUMP instruction in the most common case.
IE
In the most common case (expr is true) optimization, instead of reading a JUMP instruction, discarding it, doing the statement, and then jumping, it jumps and then does the statement (notice the lack of discarded jump).
Expression: Something that resolves to a numeric value (0 for false, nonzero for true)
This is the big one, rest are things you probably did know.
Switch syntax is
switch (expression) statement
Code: Select all
switch (x) {
case 1:
while (c < 5) {
a += 5;
doSomething();
case 3:
c++;
}
}
For syntax is
for (expression1; expression2; expression3) statement
All expressions in for are optional
Code: Select all
for (i < 5;q = q + 1;doSomething());
Code: Select all
expression1;
while (expression2) {
statement
expression3; //except that continue; points to the start of this line
}
IE
Code: Select all
FALSE
+---------------+ L
| v
if (expr) statment1 else statement2
| ^
+----------------+ M
TRUE
expr
Test
JumpF L
statement1
Jump M
L: statement2
M:
Common-case-first optimization:
Test
JumpT L
statement2
Jump M
L: statement1
M: