W3C libwww C-Style

Special Language Features

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:

Reserved words

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

Specific Problems

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()
Many platforms do not support this feature or dump core
malloc()
One some platforms malloc() returns NULL if size is 0.
const and static
some versions of gcc have problems with variables declared both static and const.
Preprocessor statements
Comments
Don't use // 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.


Henrik Frystyk Nielsen
@(#) $Id: Language.html,v 1.10 1996/12/09 03:23:12 jigsaw Exp $