1
0

uip-code-style.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /* This is the official code style of uIP. */
  2. /**
  3. * \defgroup codestyle Coding style
  4. *
  5. * This is how a Doxygen module is documented - start with a \defgroup
  6. * Doxygen keyword at the beginning of the file to define a module,
  7. * and use the \addtogroup Doxygen keyword in all other files that
  8. * belong to the same module. Typically, the \defgroup is placed in
  9. * the .h file and \addtogroup in the .c file.
  10. *
  11. * @{
  12. */
  13. /**
  14. * \file
  15. * A brief description of what this file is.
  16. * \author
  17. * Adam Dunkels <adam@sics.se>
  18. *
  19. * Every file that is part of a documented module has to have
  20. * a \file block, else it will not show up in the Doxygen
  21. * "Modules" * section.
  22. */
  23. /* Single line comments look like this. */
  24. /*
  25. * Multi-line comments look like this. Comments should prefferably be
  26. * full sentences, filled to look like real paragraphs.
  27. */
  28. #include "uip.h"
  29. /*
  30. * Make sure that non-global variables are all maked with the static
  31. * keyword. This keeps the size of the symbol table down.
  32. */
  33. static int flag;
  34. /*
  35. * All variables and functions that are visible outside of the file
  36. * should have the module name prepended to them. This makes it easy
  37. * to know where to look for function and variable definitions.
  38. *
  39. * Put dividers (a single-line comment consisting only of dashes)
  40. * between functions.
  41. */
  42. /*---------------------------------------------------------------------------*/
  43. /**
  44. * \brief Use Doxygen documentation for functions.
  45. * \param c Briefly describe all parameters.
  46. * \return Briefly describe the return value.
  47. * \retval 0 Functions that return a few specified values
  48. * \retval 1 can use the \retval keyword instead of \return.
  49. *
  50. * Put a longer description of what the function does
  51. * after the preamble of Doxygen keywords.
  52. *
  53. * This template should always be used to document
  54. * functions. The text following the introduction is used
  55. * as the function's documentation.
  56. *
  57. * Function prototypes have the return type on one line,
  58. * the name and arguments on one line (with no space
  59. * between the name and the first parenthesis), followed
  60. * by a single curly bracket on its own line.
  61. */
  62. void
  63. code_style_example_function(void)
  64. {
  65. /*
  66. * Local variables should always be declared at the start of the
  67. * function.
  68. */
  69. int i; /* Use short variable names for loop
  70. counters. */
  71. /*
  72. * There should be no space between keywords and the first
  73. * parenthesis. There should be spaces around binary operators, no
  74. * spaces between a unary operator and its operand.
  75. *
  76. * Curly brackets following for(), if(), do, and case() statements
  77. * should follow the statement on the same line.
  78. */
  79. for(i = 0; i < 10; ++i) {
  80. /*
  81. * Always use full blocks (curly brackets) after if(), for(), and
  82. * while() statements, even though the statement is a single line
  83. * of code. This makes the code easier to read and modifications
  84. * are less error prone.
  85. */
  86. if(i == c) {
  87. return c; /* No parentesis around return values. */
  88. } else { /* The else keyword is placed inbetween
  89. curly brackers, always on its own line. */
  90. c++;
  91. }
  92. }
  93. }
  94. /*---------------------------------------------------------------------------*/
  95. /*
  96. * Static (non-global) functions do not need Doxygen comments. The
  97. * name should not be prepended with the module name - doing so would
  98. * create confusion.
  99. */
  100. static void
  101. an_example_function(void)
  102. {
  103. }
  104. /*---------------------------------------------------------------------------*/
  105. /* The following stuff ends the \defgroup block at the beginning of
  106. the file: */
  107. /** @} */