coding_style: Fix enum name
PATCH 1/2 coding_style: Fix enum name
--- doc/coding-style.txt | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
doc/coding-style.txt +1 -1
@@ -167,7 +167,7 @@ enum animal_type { If the enum contents have values (e.g. from specification) the preferred formatting is as follows: -enum animal type { +enum animal_type { ANIMAL_TYPE_FOUR_LEGS = 4, ANIMAL_TYPE_EIGHT_LEGS = 8, ANIMAL_TYPE_TWO_LEGS = 2,
Signature · 1 line
1.7.2.3
PATCH 2/2 coding_style: Add case for enum as switch variable
--- doc/coding-style.txt | 32 ++++++++++++++++++++++++++++++++ 1 files changed, 32 insertions(+), 0 deletions(-)
doc/coding-style.txt +32 -0
@@ -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,
Signature · 1 line
1.7.2.3
Hi Yang,
Quoted 4 lines · Yang Gu
--- doc/coding-style.txt | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
Both patches have been applied, thanks.
Regards,
-Denis