diff options
author | Yang Gu <yang.gu@intel.com> | 2010-11-02 22:21:37 +0800 |
---|---|---|
committer | Denis Kenzior <denkenz@gmail.com> | 2010-11-02 14:58:20 -0500 |
commit | e9b41e953fdaeda7f36cf8ef280c7a074cd72efe (patch) | |
tree | 6303987c501cd3ecaed17c7e1aebd66514e53051 /doc/coding-style.txt | |
parent | bd816f4063dd24ed4f4300fb326854f59ea8ebb4 (diff) | |
download | ofono-e9b41e953fdaeda7f36cf8ef280c7a074cd72efe.tar.bz2 |
coding_style: Add case for enum as switch variable
Diffstat (limited to 'doc/coding-style.txt')
-rw-r--r-- | doc/coding-style.txt | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/doc/coding-style.txt b/doc/coding-style.txt index 9e5a8111..6fa355ed 100644 --- a/doc/coding-style.txt +++ b/doc/coding-style.txt @@ -173,6 +173,38 @@ enum animal_type { ANIMAL_TYPE_TWO_LEGS = 2, }; +M12: Enum as switch variable +==================== + +If the variable of a switch is an enum, you must not include a default in +switch body. The reason for this is: If later on you modify the enum by adding +a new type, and forget to change the switch accordingly, the compiler will +complain the new added type hasn't been handled. + +Example: + +enum animal_type { + ANIMAL_TYPE_FOUR_LEGS = 4, + ANIMAL_TYPE_EIGHT_LEGS = 8, + ANIMAL_TYPE_TWO_LEGS = 2, +}; + +enum animal_type t; + +switch (t) { +case ANIMAL_TYPE_FOUR_LEGS: + ... + break; +case ANIMAL_TYPE_EIGHT_LEGS: + ... + break; +case ANIMAL_TYPE_TWO_LEGS: + ... + break; +default: // wrong + break; +} + O1: Shorten the name ==================== Better to use abbreviation, rather than full name, to name a variable, |