Incautious use of semicolons
suggest changeBe careful with semicolons. Following example
if (x > a);
a = x;
actually means:
if (x > a) {}
a = x;
which means x
will be assigned to a
in any case, which might not be what you wanted originally.
Sometimes, missing a semicolon will also cause an unnoticeable problem:
if (i < 0)
return
day = date[0];
hour = date[1];
minute = date[2];
The semicolon behind return is missed, so day=date[0] will be returned.
One technique to avoid this and similar problems is to always use braces on multi-line conditionals and loops. For example:
if (x > a) {
a = x;
}
Found a mistake? Have a question or improvement idea?
Let me know.
Incautious use of semicolons
Table Of Contents
5 Arrays
12 Assertion
13 Linked lists
15 X-macros
17 Pointers
18 Structs
22 Compilation
24 Bit-fields
25 Strings
30 Valgrind
31 Typedef
35 Boolean
38 Declarations
47 Atomics
49 Enumerations
55 Side effects
57 Constrains
58 Inlining
59 Unions
63 Comments
64 Contributors