git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH/RFC] Documenation update: use of braces in if/else if/else chain

From
Leila Muhtasib <muhtasib@gmail.com>
Date
Jun 10, 2012, 17:26 UTC
Message-ID
<1339349190-84552-1-git-send-email-muhtasib@gmail.com>
Signed-off-by: Leila Muhtasib <muhtasib@gmail.com>
---
Does the below more accruately represent the coding guidelines?
I can modify it, if it doesn't.

Thanks, Leila

 Documentation/CodingGuidelines |   23 ++++++++++++++++++++---
 1 files changed, 20 insertions(+), 3 deletions(-)
diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines
index 4557711..ea90521 100644
--- a/Documentation/CodingGuidelines
+++ b/Documentation/CodingGuidelines
@@ -117,9 +117,26 @@ For C programs:
 
    is frowned upon.  A gray area is when the statement extends
    over a few lines, and/or you have a lengthy comment atop of
-   it.  Also, like in the Linux kernel, if there is a long list
-   of "else if" statements, it can make sense to add braces to
-   single line blocks.
+   it.  Also, like in the Linux kernel, if one of the
+   "if/else if/else" chain has a multiple statement block, use {}
+   even for a single statement block in that chain. And "else"
+   should come on the same line as the closing "}" of its "if" block.
+
+	//correct
+	if (bla) {
+		x = 1;
+		...
+	} else {
+		x = 2;
+	}
+
+	//incorrect
+	if (bla) {
+		x = 1;
+		...
+	}
+	else
+		x = 2;
 
  - We try to avoid assignments inside if().
 
-- 
1.7.7.5 (Apple Git-26)
Next: Jonathan Nieder
Message 1 of 3 in “Documenation update: use of braces in if/else if/else chain”
  1. Documenation update: use of braces in if/else if/else chainLeila Muhtasib, Jun 10, 2012
  2. Jonathan NiederJun 10, 2012
  3. LeilaJun 10, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.