libsofia-sip-ua 1.12.11devel
|
This document gives general guidelines on generic C style and code formatting within Sofia-SIP.
The guidelines include identifier naming conventions, indenting convention, and tool usage directions.
Please note that C style is always a matter of taste.
Generally, identifiers within each module are prefixed with the name of that module. For instance, the functions within http parser module http have prefix http_
. Identifiers composed of multiple words have an underscore "_" between the words, the words themselves are in lower case. For instance, http_request_create().
Macros should be in upper case. File names should be in lower case using underscore as delimiter if needed.
Normal typedefs have suffix _t
, however, function types have suffix _f
. The enum names also sometimes have _e
, struct names have _s
and union names _u
.
It is recommended that type itself is typedef'ed, not a pointer to the type. It should be clear from variable declaration if the variable is a pointer or not.
Struct and union members should have common prefix. For instance,
This prefix makes it easier to find where members are used.
Indentation in Sofia-SIP C code generally follows the K&R style with indent of 2 characters (so you can use the default "GNU" c-style in Emacs). The maximum line length should be 80 characters.
For example,
The default indentation can be achieved with GNU indent with options
Loops without condition use for
(;;) instead of
while
(1).
There should be whitespace on both sides of infix operators, except .
or ->
, which require no space, or ,
(comma) which requires space only after). There should be whitespace between a keyword and parenthesis following it, but no whitespace between an identifier and parenthesis following it. E.g.,