mirror of
https://github.com/paparazzi/paparazzi.git
synced 2026-05-27 17:06:31 +08:00
[doxygen] Updated code style guide
* added example for if/else * added Eclipse code style * syncronized all examples with the guide
This commit is contained in:
+27
-7
@@ -22,7 +22,9 @@ Feedback would be welcome to improve the Paparazzi guidelines.
|
|||||||
/** @page stylec C Style Guide
|
/** @page stylec C Style Guide
|
||||||
|
|
||||||
This page contains guidelines for writing new C source code for the
|
This page contains guidelines for writing new C source code for the
|
||||||
Paparazzi project.
|
Paparazzi project. If you are using Eclipse, download Paparazzi code
|
||||||
|
style for Eclipse here:
|
||||||
|
http://paparazzi.enac.fr/wiki/File:Paparazzi_code_profile_eclipse.zip
|
||||||
|
|
||||||
@section styleformat Formatting Guide
|
@section styleformat Formatting Guide
|
||||||
|
|
||||||
@@ -58,8 +60,7 @@ static inline int cube(int x) { return x * x * x; }
|
|||||||
- define static functions before first usage to avoid forward declarations.
|
- define static functions before first usage to avoid forward declarations.
|
||||||
- Functions should have no space between its name and its parameter list:
|
- Functions should have no space between its name and its parameter list:
|
||||||
@code
|
@code
|
||||||
int32_t f(int32_t x1, int32_t x2)
|
int32_t f(int32_t x1, int32_t x2) {
|
||||||
{
|
|
||||||
...
|
...
|
||||||
int32_t y = f(x1, x2 - x1);
|
int32_t y = f(x1, x2 - x1);
|
||||||
...
|
...
|
||||||
@@ -71,14 +72,12 @@ int32_t f(int32_t x1, int32_t x2)
|
|||||||
- specify a default case
|
- specify a default case
|
||||||
- prefer an enum over defines for the different states
|
- prefer an enum over defines for the different states
|
||||||
@code
|
@code
|
||||||
enum state
|
enum state {
|
||||||
{
|
|
||||||
STATE_FOO = 1,
|
STATE_FOO = 1,
|
||||||
STATE_BAR = 2
|
STATE_BAR = 2
|
||||||
};
|
};
|
||||||
|
|
||||||
switch( state )
|
switch (state) {
|
||||||
{
|
|
||||||
case STATE_FOO:
|
case STATE_FOO:
|
||||||
foo();
|
foo();
|
||||||
break;
|
break;
|
||||||
@@ -90,6 +89,27 @@ switch( state )
|
|||||||
}
|
}
|
||||||
@endcode
|
@endcode
|
||||||
|
|
||||||
|
@section styleif If statements
|
||||||
|
|
||||||
|
- return statement on the new line even for ""simple if"" case
|
||||||
|
@code
|
||||||
|
if (TRUE) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (x < other.x) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
else if (x > other.x) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
@endcode
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@section stylecpp Preprocessor directives
|
@section stylecpp Preprocessor directives
|
||||||
- For conditional compilation use @c \#if instead of @c \#ifdef.
|
- For conditional compilation use @c \#if instead of @c \#ifdef.
|
||||||
Someone might write code like:
|
Someone might write code like:
|
||||||
|
|||||||
Reference in New Issue
Block a user