Scor­pio News


October–December 1988 – Volume 2. Issue 4.

Page 11 of 35

An Introduction to C

by R.C. Pearce

The C programming language is still fairly young, though by now well established as one of the major ones. Its development was very much tied in with the development of the UNIX operating system for PDP-11 and VAX mainframes, and a good C compiler will always attempt to create a UNIX-like environment. It is worth noting that much of UNIX was written in C, and all input/​output in C is modelled on UNIX.

Like the earlier language B, C is derived largely from the BCPL language, though it differs from those two in supporting ‘type’d data (ie. integers, reals etc.). It is a very concise language (which as we all know often equates to unreadable, though it is quite possible to write very clear, tidy and self-explanatory code) and places few restrictions on the programmer, thus allowing fast and efficient code to be written. This leeway raises some doubts as to the validity of the term “high level” when referring to C, and indeed it is commonly used for low level code (the Gemini BIOS 3; FORMAT and WHIG programs were written in C, as was GENSYS).

Program Structure

Since C is a compiled language, programs must be entered using an editor such as WordStar or PEN. I use HiSoft C so I enter programs in ED80, the HiSoft editor. The layout of a C program does not matter, but it is obviously best to lay it out neatly and in a way which clearly shows the structure. White space can be added wherever it helps and comments can be included anywhere where white space is allowed.

A C program consists of a list of function definitions and global variable definitions. Also there may (and usually will) be some “pre-processor directives”. Actual code only occurs within function definitions. There is no program in the way PASCAL has, since the main program is a function called main( ).

A function definition starts with a type declaration like that of a variable except for the parentheses which indicate a function. This is followed by type declarations for the arguments of the function and then the main code. Unlike PASCAL, the argument types are defined outside the parameter list. For example :–

Page 11 of 35