Let us first start with some general language rules for how to provide maintainable and portable C code. One of the main objectives is to use the ANSI C and the POSIX.1 standard wherever possible in order to maximum portability. This means that we can not use (unfortunately!) neither objective C nor C++. However, we also want to support original Kernighan Ritchie C compilers and C++ compilers which brings in two important aspects in the coding style:
It is important that there are no reserved words used as variable names, function calls etc in our code. Some of the more common problem makes are listed below but see also Identifiers
new
this
class
template
operator
friend
catch
As the world is not ideal, there are some traps that often show up when coding after these standards. This sections gives an overview of the more serious ones:
memmove()
malloc()
malloc()
returns NULL
if size
is 0.
static
and const
.
#elif
. Basic cpp doesn't know it.
//
as a comment delimiter. This is not supported by
ANSI C.
Remember that your code should compile without warnings under an ANSI C compiler such as gcc with all warnings enabled BUT this is not enough. The more native compilers you can use the better - gcc is not the only example of an ANSI compiler.