Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Switches, default, and enums
#6
When writing code for safety-critical systems, I have always considered treating all RAM locations to be \"volatile\" in nature. If I have code which can set a 16 bit unsigned integer (represeting an enum) explicitly to the values of 0, 1, 2, and 3, I also always handle the cases of it being any other value the storage may select, i.e. 4 to 65535.

Given
Code:
typedef enum {
   red,
   green,
   blue
} color_t;

   ...
   color_t color;
   ...
   color = red;
   ...
   {
      switch (color) {
      case red:
         /* do something */
         break;
      case green:
         /* do something */
         break;
      case blue:
         /* do something */
   }

Treat color to be volatile, and assume that a failure mechanisum WILL exist to randomly set it.
Given this, the need for the default clause is not in question. (imho)

George


Messages In This Thread

Forum Jump:


Users browsing this thread: 2 Guest(s)