Skip to contentSkip to conversation

Documentation: allow multiple return statements per function

PATCH In review Dan Carpenter 3 participants 3 messages May 15, 2013 – May 16, 2013 Documentation

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Documentation: allow multiple return statements per function

A surprising number of newbies interpret this section to mean that only one return statement is allowed per function. Part of the problem is that the "one return statement per function" rule is an actual style guideline that people are used to from other projects.

Documentation/CodingStyle +2 -1
index e00b8f0..7fe0546 100644
@@ -389,7 +389,8 @@ Albeit deprecated by some people, the equivalent of the goto statement is
 used frequently by compilers in form of the unconditional jump instruction.
 
 The goto statement comes in handy when a function exits from multiple
-locations and some common work such as cleanup has to be done.
+locations and some common work such as cleanup has to be done.  If there is no
+cleanup needed then just return directly.
 
 The rationale is:
 
#1 lore raw
Quoted 12 lines · Dan Carpenter

A surprising number of newbies interpret this section to mean that only one return statement is allowed per function. Part of the problem is that the "one return statement per function" rule is an actual style guideline that people are used to from other projects.

Documentation/CodingStyle +0 -0
index e00b8f0..7fe0546 100644

Documentation/CodingStyle Albeit deprecated by some people, the equivalent of the goto statement is · line 393

Quoted 6 lines
Documentation/CodingStyle +2 -1
@@ -389,7 +389,8 @@ Albeit deprecated by some people, the equivalent of the goto statement is
 used frequently by compilers in form of the unconditional jump instruction.
 
 The goto statement comes in handy when a function exits from multiple
-locations and some common work such as cleanup has to be done.
+locations and some common work such as cleanup has to be done.  If there is no
+cleanup needed then just return directly.

Agreed with this rephrasing.

Quoted 4 lines
Documentation/CodingStyle +0 -0
 The rationale is:
 
 
#2 lore raw
In reply to Dan Carpenter
Quoted 6 lines · Dan Carpenter

A surprising number of newbies interpret this section to mean that only one return statement is allowed per function. Part of the problem is that the "one return statement per function" rule is an actual style guideline that people are used to from other projects.

Ack, please forward to trivial tree.

Rob