Using loops and control constructs
For the for-loop index variable:
- Use a long type variable whenever possible. Under ILP32, long and int are equivalent, but long is better for portability to an LP64 environment.
- Use the auto or register storage class over the extern or static storage class.
- If you use an enum variable, expand
the variable to be a fullword by using the ENUMSIZE compiler option
or by placing a large defined value at the end of your enum variable,
as follows:
enum animals { ant cat, dog, robin, last_animal = INT_MAX; };
- Do not use the address operator (&) on the index.
- The index should not be a member of a union.
For if statements:
- Order the if conditions efficiently; put the most decisive
tests first and the most expensive tests last.
By performing the most common tests first, you increase the efficiency of your code; fewer tests are required to meet the test conditions.
if (command.is_classg && command.len == 6 && !strcmp (command.str, "LOGON")) /* call to strcmp() most expensive */ logon ();