Why
If you'd like to contribute code to tla, it helps if you mimic existing style. No matter what you personally would prefer, the style isn't up for debate. There are far better things to argue about.
Braces and indents
tla style uses 2-space indents. Braces are indented GNU-style, that is
if (foo)
{
bar ();
baz ();
}
Inline whitespace
tla style puts whitespace around operators, e.g.
if (foo != bar) baz (foo);
Spaces also appear around parentheses, but not between them.
Control structures
The statement portion of an if, for, do, or while always goes on a separate line from the condition, even if no braces are required. See example above.
Types
NULL is unused. Testing for validity should use 0 instead of NULL. !foo is also often used.
The string type is t_uchar *.
Function declarations and definitions
static int
foo (type1 output_arg1
type2 output_arg2
type3 input_arg1
type4 input_arg2);
- Return types are usually used to indicate status.
- Return types are declared on their own line.
- Arguments that are used to provide output should appear before arguments that provide input.
- If arguments lists span multiple lines, they should be indented to match the position of the first argument.
Helper functions should ususally be declared static.
Other functions should be declared extern.
- Static functions are declared at the beginning of their .c file, not the corresponding .h file.
- Functions with external linkage should be declared in their corresponding .h file.
External functions should have names beginning with "arch_".
