Merge pull request #1963 from yatch/pr/code-style

Update doc/code-style.c
This commit is contained in:
Simon Duquennoy 2016-12-05 13:40:36 +01:00 committed by GitHub
commit f6439121b4

View file

@ -7,15 +7,13 @@
* belong to the same module. Typically, the \defgroup is placed in * belong to the same module. Typically, the \defgroup is placed in
* the .h file and \addtogroup in the .c file. * the .h file and \addtogroup in the .c file.
* *
* The Contiki source code contains a GNU Indent script that can * The Contiki source code contains an Uncrustify configuration file,
* automatically format a C code file to match the Contiki code * uncrustify.cfg, under tools/code-style and small helper scripts are
* style. The Indent configuration is in contiki/tools/indent.pro and * provided at the same place. Note that this is not a silver bullet -
* a small helper script is in contiki/tools/contiki-indent. Note that * for example, the script does not add separators between functions,
* this is not a silver bullet - for example, the script does not add * nor does it format comments correctly. The script should be treated
* separators between functions, nor does it format comments * as an aid in formatting code: first run the formatter on the source
* correctly. The script should be treated as an aid in formatting * code, then manually edit the file.
* code: first run the formatter on the source code, then manually
* edit the file.
* *
* @{ * @{
*/ */
@ -74,22 +72,22 @@ static int flag;
* between the name and the first parenthesis), followed * between the name and the first parenthesis), followed
* by a single curly bracket on its own line. * by a single curly bracket on its own line.
*/ */
void int
code_style_example_function(void) code_style_example_function(char c)
{ {
/* /*
* Local variables should always be declared at the start of the * Local variables should always be declared at the start of the
* function. * function.
*/ */
int i; /* Use short variable names for loop int i; /* Use short variable names for loop
counters. */ counters. */
/* /*
* There should be no space between keywords and the first * There should be no space between keywords and the first
* parenthesis. There should be spaces around binary operators, no * parenthesis. There should be spaces around binary operators, no
* spaces between a unary operator and its operand. * spaces between a unary operator and its operand.
* *
* Curly brackets following for(), if(), do, and case() statements * Curly brackets following for(), if(), do, and switch() statements
* should follow the statement on the same line. * should follow the statement on the same line.
*/ */
for(i = 0; i < 10; ++i) { for(i = 0; i < 10; ++i) {
@ -100,12 +98,25 @@ code_style_example_function(void)
* are less error prone. * are less error prone.
*/ */
if(i == c) { if(i == c) {
return c; /* No parentesis around return values. */ return 1; /* No parentesis around return values. */
} else { /* The else keyword is placed inbetween } else { /* The else keyword is placed inbetween
curly brackers, always on its own line. */ curly brackers, always on its own line. */
c++; c++;
} }
} }
/*
* Indent "case" statement and "default" label by two spaces in "switch"
* statement.
*/
switch(c) {
case 19:
return 1;
default:
break;
}
return 0;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/* /*