Changeset 844


Ignore:
Timestamp:
Apr 22, 2006, 9:14:26 PM (15 years ago)
Author:
Sam Hocevar
Message:
  • Wrote the C coding style documentation.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/doc/style.dox

    r836 r844  
    33/** \page style Coding style
    44
    5  Code qui fait des warnings == code de porc == deux baffes dans ta gueule
     5 \section sty1 General guidelines
     6
     7 A pretty safe rule of thumb is: look at what has already been done and
     8 try to do the same.
     9
     10 - Tabulations should be avoided and replaced with \e eight spaces.
     11 - Indentation is generally 4 spaces.
     12 - Lines should wrap at most at 79 characters.
     13 - Do not leave whitespace at the end of lines.
     14 - Do not use multiple spaces for anything else than indentation.
     15 - Code qui fait des warnings == code de porc == deux baffes dans ta gueule
     16
     17 \section sty2 C coding style
     18
     19 Try to use short names whenever possible (\c i for indices, \c w for width,
     20 \c cv for canvas...). Macros are always uppercase, variable and function
     21 names are always lowercase. Use the underscore to separate words within
     22 names:
     23
     24 \code
     25#define BROKEN 0
     26#define MAX(x, y) ((x > y) ? (x) : (y))
     27
     28unsigned int x, y, w, h;
     29char *font_name;
     30void frobulate_every_three_seconds(void);
     31 \endcode
     32
     33 \c const is a \e suffix. It's \c char \c const \c *foo, not \c const \c char
     34 \c *foo.
     35
     36 Use spaces after commas and between operators. Do not use spaces after an
     37 opening parenthesis or before a closing one:
     38
     39 \code
     40a += 2;
     41b = (a * (c + d));
     42x = min(x1, x2, x3);
     43 \endcode
     44
     45 Do not put a space between functions and the corresponding opening
     46 parenthesis:
     47
     48 \code
     49int function(int);
     50
     51if(a == b)
     52    return;
     53 \endcode
     54
     55 Do not put parentheses around return values:
     56
     57 \code
     58return a + (b & x) + d[10];
     59 \endcode
     60
     61 Opening braces should be on a line of their own, aligned with the
     62 current block. Braces are optional for one-liners:
     63
     64 \code
     65int function(int a)
     66{
     67    if(a & 0x84)
     68        return;
     69
     70    if(a < 0)
     71    {
     72        return -a;
     73    }
     74    else
     75    {
     76        a /= 2;
     77
     78        switch(a)
     79        {
     80            case 0:
     81            case 1:
     82                return -1;
     83                break;
     84            default:
     85                return a;
     86        }
     87    }
     88}
     89 \endcode
     90
     91 \section sty3 C++ coding style
     92
     93 Nothing here yet.
    694
    795*/
Note: See TracChangeset for help on using the changeset viewer.