next up previous contents
Next: Code generation Up: Coding conventions Previous: For OCaml code   Contents

For C code

indent -kr -i8, parse: K&R, tabstops are 8 spaces long. Don't use expandtab, we want \t's here.

Example (very stupid one):

        int f(int a, int b)
        {
                while (a != 0) {
                        if (a == b) {
                                a = b;
                        } else {
                                b = c;
                        }
                        switch (c) {
                        case C1:
                                c = 1;
                                break;
                        case C2:
                                c = 2;
                                break;
                        }
                }
        }

Functions should be small (1-2 screens).

Why -kr? Because (1) K&R are right, (2) K&R are right, and (3) K&R are right. Why -i8? After 15th hour of hacking, you'll surly find out why... If you get far too far to the right with such a huge indent, it means your functions are far too big (borrowed from CodingStyle file that comes with linux kernel).



Micha³ Moskal 2001-12-03