All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] coding_style: Fix enum name
@ 2010-11-02 14:21 Yang Gu
  2010-11-02 14:21 ` [PATCH 2/2] coding_style: Add case for enum as switch variable Yang Gu
  2010-11-02 20:51 ` [PATCH 1/2] coding_style: Fix enum name Denis Kenzior
  0 siblings, 2 replies; 3+ messages in thread
From: Yang Gu @ 2010-11-02 14:21 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 532 bytes --]

---
 doc/coding-style.txt |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/doc/coding-style.txt b/doc/coding-style.txt
index 95ed50b..9e5a811 100644
--- a/doc/coding-style.txt
+++ b/doc/coding-style.txt
@@ -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,
-- 
1.7.2.3


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] coding_style: Add case for enum as switch variable
  2010-11-02 14:21 [PATCH 1/2] coding_style: Fix enum name Yang Gu
@ 2010-11-02 14:21 ` Yang Gu
  2010-11-02 20:51 ` [PATCH 1/2] coding_style: Fix enum name Denis Kenzior
  1 sibling, 0 replies; 3+ messages in thread
From: Yang Gu @ 2010-11-02 14:21 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1180 bytes --]

---
 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 9e5a811..6fa355e 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,
-- 
1.7.2.3


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] coding_style: Fix enum name
  2010-11-02 14:21 [PATCH 1/2] coding_style: Fix enum name Yang Gu
  2010-11-02 14:21 ` [PATCH 2/2] coding_style: Add case for enum as switch variable Yang Gu
@ 2010-11-02 20:51 ` Denis Kenzior
  1 sibling, 0 replies; 3+ messages in thread
From: Denis Kenzior @ 2010-11-02 20:51 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 214 bytes --]

Hi Yang,

On 11/02/2010 09:21 AM, Yang Gu wrote:
> ---
>  doc/coding-style.txt |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 

Both patches have been applied, thanks.

Regards,
-Denis

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-11-02 20:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-11-02 14:21 [PATCH 1/2] coding_style: Fix enum name Yang Gu
2010-11-02 14:21 ` [PATCH 2/2] coding_style: Add case for enum as switch variable Yang Gu
2010-11-02 20:51 ` [PATCH 1/2] coding_style: Fix enum name Denis Kenzior

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.