...
Code Block |
---|
|
#include <stdio.h>
for (int i = 0; i < 10; ++i) {
printf("i is %d", i);
}
|
Exceptions
Anchor |
---|
| MSC07MSC12-EX1MSC07 |
---|
| MSC12-EX1 |
---|
|
MSC07-CMSC12-EX1: In some situations, seemingly dead code may make software resilient. An example is the
default
label in a
switch
statement whose controlling expression has an enumerated type and that specifies labels for all enumerations of the type. (See
MSC01-C. Strive for logical completeness.) Because valid values of an enumerated type include all those of its underlying integer type, unless enumeration constants are provided for all those values, the
default
label is appropriate and necessary.
Code Block |
---|
|
typedef enum { Red, Green, Blue } Color;
const char* f(Color c) {
switch (c) {
case Red: return "Red";
case Green: return "Green";
case Blue: return "Blue";
default: return "Unknown color"; /* Not dead code */
}
}
void g() {
Color unknown = (Color)123;
puts(f(unknown));
}
|
Anchor |
---|
| MSC07MSC12-EX2MSC07 |
---|
| MSC12-EX2 |
---|
|
MSC07-CMSC12-EX2: It is permissible to temporarily remove code that may be needed later. (See
MSC04-C. Use comments consistently and in a readable fashion for an illustration.)
...