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.


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@104176 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Tilghman Lesher 2008-02-26 18:40:26 +00:00
parent bc5b59b13d
commit a616346c6d
1 changed files with 14 additions and 10 deletions

View File

@ -226,11 +226,15 @@ for (x = 0; x < 5; x++)
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:
if (foo) {
@ -376,15 +380,15 @@ you intend to parse the incoming data string.
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.
- Use the argument parsing macros to declare arguments and parse them, i.e.:
- 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!
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 @@ in having code like this:
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);