Daniel Posthuma

Powered by 🌱Roam Garden

C Programming

Programs in Plan 9 are generally written in rc, alef, or a dialect of ANSI C. The Plan 9 C dialect has some minor extensions and a few major restrictions. The most important restriction is that the compiler demands that all function definitions have ANSI prototypes and all function calls appear in the scope of a prototyped declaration of the function. Each system library has an associated header file, declaring all functions in that library. The standard Plan 9 library is called libc, so all C source files include <libc.h>. These rules guarantee that all functions are called with arguments having the expected types.

Another restriction is that the C compilers accept only a subset of the preprocessor directives. The main omission is #if. Conditional compiliation, even with #ifdef, is used sparingly in Plan 9 - only present in low-level routines in the graphics library.

Instead of UNIX's creat, Plan 9 has a create function that takes three arguments:

int create(char *file, int omode, ulong perm)

perm defines whether the returned file descriptor is to be opened for reading, writing, or both.

Plan 9 uses a 16-bit character called Unicode. To simplify the exchange of text between programs, the characters are packed into a byte stream by the UTF-8 encoding.

APE (ANSI C/POSIX Environment) comprises separate include files, libraries, and commands, conforming as much as possible to the strict ANSI C and base-level POSIX specifications.

Referenced in