1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
|
TurnServer coding style
========================
I) Code layout
---------------
The code has to follow ANSI coding standard layout. Use 2 space indentation instead
of tabs.
void foo(int barc, char** barv)
{
unsigned int test = 0;
size_t i = 0;
int run = 0;
if(test)
{
/* do something */
}
else
{
/* do other thing */
}
while(run)
{
/* do loop */
}
for(i = 0 ; i < 2 ; i++)
{
/* do other loop */
}
do
{
/* do another loop */
}while(run);
}
It is recommended to use only the C-style comments:
/* my short comment */
/* a longer comment
* on multiple lines
* ...
*/
II) Code organization
----------------------
The code has to follow these recommendations:
- 80 columns line limit;
- Always initialize your variables;
- Put "static" keyword if functions / global variables are not used outside C file (not in header file);
- Try to avoid static variables in functions (try to make reentrant things);
- Prefer using size_t/ssize_t instead of int/unsigned int when possible;
- Use "const" keyword for pointers if they should not been modified in function;
- Put a space before and after operator +/-* i.e. a + b - (c * 5) / 3);
- Put an empty line at the end of each file.
Naming has to follow these recommendations:
- File name has to be in lower case, words are separated by "_";
- Structure and function name has to be in lower case, words are separated by a "_" character (my_structure, my_function);
- Each global variable must be prefixed with "g_" (g_run).
Each file, function, structure and global variable MUST be documented using doxygen.
Here is a complete example:
/**
* \file my_file.h
* \brief Short description.
* \author Name
* \date 2008
*/
#ifndef MY_FILE_H
#define MY_FILE_H
/**
* \def PROGRAM_NAME
* \brief The program name.
*/
#define PROGRAM_NAME "MyProgram"
/**
* \struct my_struct
* \brief Short description.
*/
struct my_struct
{
int a; /**< Description of a */
char b; /**< Description of b */
};
/**
* \var g_my_var
* \brief Description of this global variable.
*/
struct my_struct* g_my_var = NULL;
/**
* \brief Doing something.
* \param a number to use
* \param b char to use
* \return 0 if success, -1 otherwise
*/
int foo(int a, char b);
#endif /* MY_FILE_H */
III) Standards
---------------
In order to compile and run on many operating systems the code has to be portable. Thus
it is strongly recommended to write code which respects C99 and POSIX standards.
|