]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - contrib/ipfilter/STYLE.TXT
MFC r368207,368607:
[FreeBSD/stable/10.git] / contrib / ipfilter / STYLE.TXT
1
2 Over time, I am moving all of the IPFilter code to what I consider a better
3 coding style than it had before.  If you submit patches, I expect them to
4 conform as appropriate.
5
6 Function Comments
7 =================
8 Preceeding each and every function, a comment block like this should
9 be present:
10
11 /* ------------------------------------------------------------------------ */
12 /* Function:    function-name                                               */
13 /* Returns:     return-type                                                 */
14 /* Parameters:  param1(I) - param1 is an input parameter                    */
15 /*              p2(O)     - p2 is an output parameter passed as an arg      */
16 /*              par3(IO)  - par3 is a parameter which is both input and     */
17 /*                          output.  Pointers to things which are used and  */
18 /*                          then get a result stored in them qualify here.  */
19 /*                                                                          */
20 /* Description about what the function does.  This comment should explain   */
21 /* any gotchas or algorithms that are used which aren't obvious to the      */
22 /* casual reader.  It should not be an excuse to not use comments inside    */
23 /* the function.                                                            */
24 /* ------------------------------------------------------------------------ */
25
26
27 Tab spacing
28 ===========
29 Tabs are to be at 8 characters.
30
31
32 Conditions
33 ==========
34 All expressions which evaluate to a boolean for a test condition, such as
35 in an if()/while() statement must involve a boolean operation.  Since C
36 has no native boolean type, this means that one of <,>,<=,>=,==,!= must
37 be present.  Implied boolean evaluations are out.
38
39 In code, the following is banned:
40
41 if (x)
42 if (!x)
43 while ((a = b))
44
45 and should be replaced by:
46
47 if (x != 0)
48 if (x == 0)
49 while ((a = b) != 0)
50
51 If pointers are involved, always compare with NULL, ie.:
52
53 if (x != NULL)
54 if (x == NULL)
55 while ((a = b) != NULL)
56
57