Docs: C struct style
Tests: changed waiting->wait backend
This commit is contained in:
parent
62e652bbcf
commit
3a5d156690
33 changed files with 60 additions and 37 deletions
|
|
@ -47,15 +47,14 @@ myfn(int par1,
|
|||
ms = NULL;
|
||||
```
|
||||
Notes:
|
||||
1. the return type of the function and all qualifers on first line (`static int`)
|
||||
2. function name and first parameter on second line, thereafter each parameter on own line
|
||||
1. The return type of the function and all qualifers on first line (`static int`)
|
||||
2. Function name and first parameter on second line, thereafter each parameter on own line
|
||||
3. Each parameter indented to match the "longest" (`my_structure`)
|
||||
4. Pointer declarations written: `type *p`, not: `type* p`.
|
||||
5. All local variables in a function declared at top of function, not inline with C-statements.
|
||||
6. Local variables can be initialized with scalars or constants, not eg malloc or functions with return values that need to be checked for errors
|
||||
7. There is a single empty line between local variable declarations and the first function statement.
|
||||
|
||||
|
||||
Function signatures are declared in include files or in forward declaration using "one-line" syntax, unless very long:
|
||||
```
|
||||
static int myfn(int par1, my_structure *par2);
|
||||
|
|
@ -123,6 +122,28 @@ files, there is only a single level of include file dependencies.
|
|||
|
||||
The drawback is that the same include file may need to be repeated in many .c files.
|
||||
|
||||
### Structs
|
||||
|
||||
Struct fields should have a prefix to distinguish them from other struct fields. The prefix should use an abbreviation of the struct name.
|
||||
|
||||
Example:
|
||||
```
|
||||
struct my_struct{
|
||||
int ms_foo;
|
||||
char *ms_string[42];
|
||||
}
|
||||
```
|
||||
where `ms_` is the prefix and is an abbreviation of `my_struct`.
|
||||
|
||||
### Global variables
|
||||
|
||||
Try to avoid global variables.
|
||||
|
||||
If you absolutely need one, try to contain it as static within a
|
||||
single C-file, ie do not declare it extern and use it elsewhere.
|
||||
|
||||
Also, always prepend a global variable with `_`, underscore.
|
||||
|
||||
## How to work in git
|
||||
|
||||
Clixon uses semantic versioning (https://semver.org).
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue