summaryrefslogtreecommitdiffstats
path: root/README.Coding
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2015-01-19 10:48:20 +0100
committerVolker Lendecke <vl@samba.org>2015-01-19 13:25:12 +0100
commit8536022a512223f0fa4711abf1cf92a1991a53b5 (patch)
treef9eaf216e24b82dda9c7aa4e316a78ec0bb74b77 /README.Coding
parent8466587c589f01d59294be36ad0b347f5d82a11f (diff)
downloadsamba-8536022a512223f0fa4711abf1cf92a1991a53b5.tar.gz
samba-8536022a512223f0fa4711abf1cf92a1991a53b5.tar.xz
samba-8536022a512223f0fa4711abf1cf92a1991a53b5.zip
README.Coding: Add hint for if-statments
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org> Autobuild-User(master): Volker Lendecke <vl@samba.org> Autobuild-Date(master): Mon Jan 19 13:25:12 CET 2015 on sn-devel-104
Diffstat (limited to 'README.Coding')
-rw-r--r--README.Coding46
1 files changed, 27 insertions, 19 deletions
diff --git a/README.Coding b/README.Coding
index 0bbba9fc45..f19399e7f2 100644
--- a/README.Coding
+++ b/README.Coding
@@ -298,25 +298,6 @@ Good Examples:
}
-Checking Pointer Values
------------------------
-
-When invoking functions that return pointer values, either of the following
-are acceptable. Use your best judgement and choose the more readable option.
-Remember that many other persons will review it:
-
- if ((x = malloc(sizeof(short)*10)) == NULL ) {
- fprintf(stderr, "Unable to alloc memory!\n");
- }
-
-or:
-
- x = malloc(sizeof(short)*10);
- if (!x) {
- fprintf(stderr, "Unable to alloc memory!\n");
- }
-
-
Primitive Data Types
--------------------
@@ -364,6 +345,33 @@ Bad Example:
ret = some_function_my_name(get_some_name());
...
+Please try to avoid passing function return values to if- or
+while-conditions. The reason for this is better handling of code under a
+debugger.
+
+Good example:
+
+ x = malloc(sizeof(short)*10);
+ if (!x) {
+ fprintf(stderr, "Unable to alloc memory!\n");
+ }
+
+Bad example:
+
+ if ((x = malloc(sizeof(short)*10)) == NULL ) {
+ fprintf(stderr, "Unable to alloc memory!\n");
+ }
+
+There are exceptions to this rule. One example is walking a data structure in
+an iterator style:
+
+ while ((opt = poptGetNextOpt(pc)) != -1) {
+ ... do something with opt ...
+ }
+
+But in general, please try to avoid this pattern.
+
+
Control-Flow changing macros
----------------------------