W3C libwww C-Style

System and Language Features to Avoid

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.

Syscalls to avoid

Actually, most system calls are to be avoided - they are very often supported via variuous libwww APIs, especially provided by the libwww utilities or core modules. Explicitly the following should not be used:

Other Problems

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
Don't use // for comments. 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.13 1999/12/01 09:28:15 kahan Exp $