next up previous contents
Next: Linkers Up: Computer Languages Previous: Assembly Languages

The C Programming Language and Compiler

  Writing large programs in assembly language is a difficult and time consuming task. It is prone to error and the resulting program is not portable, being tied to one particular processor family. It is far better to use a machine independent language higher level language like C[7, The C Programming Language,]. C allows you to describe programs in terms of their logica and the data that they operate on. Special programs called compilers read the C program and translate it into assembly language, generating machine specific code from it. A good compiler can generate assembly instructions that are very nearly as efficient as those written by a good assembly programmer. Most of the Linux kernel is written in the C language. The following C fragment:

        if (x != y)
                x = y ;
performs exactly the same operations as the assembly code above. If the contents of the variable x are not the same as the contents of variable y then the contents of y will be copied to x. C code is organized into routines which each perform a task. Routines may return any value or data type supported by C. Large programs like the Linux kernel comprise many seperate C source modules each with its own routines and data structures. These C source code modules group together logical functions such as file system handling code.

C supports many types of variables, a variable is a location in memory which can be referenced by a symbolic name. In the above C fragment x and y refer to locations in memory. The programmer does not care where in memory the variables are put, it is the linker which has to worry about that. Some variables contain different sorts of data, integer and floating point and others are pointers. Pointers are variables which contain the address, the location in memory of more data. C allows you bundle together related variables into data structures. For example,

        struct {
                int i ;
                char b ;
        } my_struct ;
is a data structure called my_struct which contains two elements, an integer (32 bits of data storage) called i and a character (8 bits of data) called b.


next up previous contents
Next: Linkers Up: Computer Languages Previous: Assembly Languages

David A. Rusling
david.rusling@reo.mts.dec.com