-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstyleguide.txt
62 lines (46 loc) · 1.68 KB
/
styleguide.txt
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
This is a poorly written and incomplete styleguide. Feel free to change
this with your preferred style. After project 0, this should not change.
This should serve to keep a consistent style between authors.
WHITESPACE:
- no tabs, use spaces
- tabstops at 2, eg
int main() {
if (x)
do something;
}
VARIABLE NAMES:
- camel case, eg 'varName'
- when declaring pointers, asterisk should be next to variable name, ex:
int *myPtr;
This is particularly nice when declaring several pointers:
int *myPtr, *anotherPtr; as opposed to
int* myPtr, * anotherPtr;
BLOCKS:
- open curly braces on same line, eg
int function() {
// some function
}
COMMENTS:
- Multiline comments for functions, single line comments elsewhere
/*
* This function has some functionality
*/
int function() {
if (x) // do something if x
do something;
}
/* this function is private to this file */
static int function() {
int val = something;
return val; // return val
}
MULTIPLE FILE PROGRAMS:
- Public data should be DECLARED in header files (.h), for example
"GlobalData" struct and "extern GlobalData globalDataMem"
- Private data should be declared in c files, for example
MeasureData (exclusively used by measure.c) should be declared
in measure.c, not measure.h
- DEFINITIONS go into c files (.c), for example
"GlobalData globalDataMem = { ... }"
Note that globalDataMem is defined in globals.c, but is declared in
globals.h as "extern ..." so the variable has external linkage