[svn-commits] tilghman: trunk r104176 - /trunk/doc/CODING-GUIDELINES

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Feb 26 12:40:27 CST 2008


Author: tilghman
Date: Tue Feb 26 12:40:26 2008
New Revision: 104176

URL: http://svn.digium.com/view/asterisk?view=rev&rev=104176
Log:
1) Make braces mandatory for if/for/while, even around single statements.
2) Revise the argument parsing section, showing use of the standard macros.
3) Fix a typo.

Modified:
    trunk/doc/CODING-GUIDELINES

Modified: trunk/doc/CODING-GUIDELINES
URL: http://svn.digium.com/view/asterisk/trunk/doc/CODING-GUIDELINES?view=diff&rev=104176&r1=104175&r2=104176
==============================================================================
--- trunk/doc/CODING-GUIDELINES (original)
+++ trunk/doc/CODING-GUIDELINES Tue Feb 26 12:40:26 2008
@@ -226,10 +226,14 @@
 instead do:
 for (x = 0; x < 5; x++) {
 	if (foo) {
-		if (bar)
+		if (bar) {
 			baz();
+		}
 	}
 }
+
+- Always use braces around the statements following an if/for/while construct,
+even if not strictly necessary, as it reduces future possible problems.
 
 - Don't build code like this:
 
@@ -376,15 +380,15 @@
 		mydata = ast_strdupa(data);
 
 
-- Separating arguments to dialplan applications and functions
-Use ast_app_separate_args() to separate the arguments to your application
-once you have made a local copy of the string.
-
-- Parsing strings with strsep
-Use strsep() for parsing strings when possible; there is no worry about
-'re-entrancy' as with strtok(), and even though it modifies the original
-string (which the man page warns about), in many cases that is exactly
-what you want!
+- Use the argument parsing macros to declare arguments and parse them, i.e.:
+
+	AST_DECLARE_APP_ARGS(args,
+		AST_APP_ARG(arg1);
+		AST_APP_ARG(arg2);
+		AST_APP_ARG(arg3);
+	);
+	parse = ast_strdupa(data);
+	AST_STANDARD_APP_ARGS(args, parse);
 
 - Create generic code!
 If you do the same or a similar operation more than one time, make it a
@@ -463,7 +467,7 @@
 	else
 		newstr = NULL;
 
-However, the ast_strdup and ast_strdup functions will happily accept a NULL
+However, the ast_strdup and ast_strdupa functions will happily accept a NULL
 argument without generating an error.  The same code can be written as:
 	
 	newstr = ast_strdup(str);




More information about the svn-commits mailing list