File: CodingStandars.tex

package info (click to toggle)
gems 1.1-3
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, sarge
  • size: 288 kB
  • ctags: 285
  • sloc: ansic: 1,514; makefile: 147
file content (161 lines) | stat: -rw-r--r-- 3,379 bytes parent folder | download | duplicates (4)
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
\documentclass[11pt]{article}
%\usepackage [spanish]{babel}
%\usepackage[latin1] {inputenc}

\title{Coding Standards}
\author{Emiliano Castagnari <ecastag@fi.uba.ar>}

\begin{document}

\tableofcontents
\newpage

\section{Files}
Every source code file must start with the filename, author(s), a short
description of the file contents, copyright notice and the abbreviated 
GPL notice.

\section{Modules}
The inclusion of header files (\#include) and declarations of macros and
constants (\#define) must be made at the beginning of the .c source file,
unless it is necessary to make it in the module header file (.h) (eg, when
other modules reference the same definition).

\section{Tabs}
Indentation is made with tab characters, except for comments used at the
right of the code, where spaces should be used instead.

\section{Screen width}
When possible, the 80 character width must be respected.

\section{Data types}
Data types should be defined following this scheme:\\

 \begin{center}
  \begin{tabular}{l|l|l|l}
   Data type & Prefix & Suffix & Example \\
   \hline
   Structures  & t\_     &    -   & t\_node \\
   Other       &    -    & \_t    & node\_t \\
   \hline
  \end{tabular}
 \end{center}


\section{Functions and prototypes}
Functions should not be declared inside other functions, and their prototypes
must be declared in the header file.

The syntax must be as follows:

\begin{verbatim}
/* Function prototype (in header file) */
/* Parameter names are optional. */
return_type function(type1, type2 *, type3);

/* Function implementation */
/* Short description of the function (recommended). */
return_type function(type1 FirstVariable, type2 *SecondVariable,
	type3 ThirdVariable)
{
    ...
    statements;
    ...
}
\end{verbatim}


\section{Blocks}
The {\bf conditional blocks}, {\bf control structures} and {\bf
iterative cycles} must be indented as follows:

If the block has only one statement:

\begin{verbatim}
/*...*/
if(<condition>) statement;
else statement;

/* alternatively */
if(<condition>) 
    statement;
else 
    statement;

for(statement1; <condition>; statement3) statement;

/* alternatively */
for(statement1; <condition>; statement3) 
    statement;

while(<condition>) statement;

/* alternatively */
while(<condition>) 
    statement;
  
 /*...*/
\end{verbatim}

General case (more than one statement in the block):

\begin{verbatim}
/*...*/
if(<condition>)
{
    statement1;
    statement2;
    /* ... */
} 
else 
{
    statement1;
    statement2;
    /* ... */
}

for(statement1; <condition>; statement3) 
{
    statement1;
    statement2;
    /* ... */
}

while(<condition>)
{
    statement1;
    statement2;
    /* ... */
}
\end{verbatim}

If a control structure is nested inside another one, the use of \{\} is
mandatory, especially with 'if' structures.

\begin{verbatim}
if(...)
{
	if(...)
	{
		...
	}
	else do_something();
}
\end{verbatim}

\section{indent(1)}

It is possible to use the \verb|indent(1)| tool to apply the proposed
indentation to any source file. To do this, the command line should be:

\begin{verbatim}
  $ indent -bli0 -nsob -di1 -npsl -npcs -ss -bls -i4 -ts4 -lc80 -l80 <file(s)>
\end{verbatim}

The only problem with this approach are the comments at the right of the code,
because \verb|indent| uses tabs for them, instead of spaces.

(Note that tab size has been set to 4 spaces).

\end{document}