Using <b>safe-c</b>




Document: The safe-c User Guide

next Overview
up The safe-c User Guide
gif What is a Module anyway?

Using safe-c

As with any free-standing C module, two separate issues or problems arise in using the safe-c module:

The first problem, of telling the compiler what the allowed interface to safe-c is, is solved by inserting the following preprocessor directive close to the top of your source file, before any other reference to safe-c entities:

  #include <safe-c.h>

The effect of this directive is that, during the compilation, the file safe-c.h is searched for in certain directories. Assuming it is found, then its text is incorporated into the compilation exactly as it it had been part of your source file. The file safe-c.h is the header file for the safe-c module and, as such, contains declarations of all the entities (constants, data types, functions) provided by safe-c. Thus, when the compiler subsequently encounters references to these entities in your code, it can recognise or decide whether they are valid. For example, safe-c.h contains a prototype for each function. This warns the compiler of the existence, in the safe-c module, of the function, and also specifies how many arguments (if any), of what types, the function can accept. Then when the compiler encounters an attempt to invoke the function, it can check whether the correct number of arguments, of the correct types, are present.

It might seem that the second problem - that of subsequently finding the compiled version of safe-c and combining it with the compiled version of your own file, in order to produce the complete executable program - simply should not arise. Surely, if the compiler is told, by the inclusion of safe-c.h, that your program makes use of facilities of safe-c, that should prompt the compiler to also look for the compiled version of safe-c, and incorporate it into the executable file?

However, few things in computer programming are as simple as they seem.

The #include directive specifies that the text of another file must be incorporated into the translation phase of the compile - i.e. while translating your source file into object code. It does not stipulate anything about what object files should subsequently be linked together to create the executable file. Indeed, it must not. This is because, in the general case, there is no simple or necessary one-to-one relationship between header files and object files. So, in the general case, stipulations of what header files to include during translation, and what object files to combine during linkage, must be kept separate.

Specifying to the compiler to include the safe-c object file in the linkage phase simply requires an additional parameter to be placed in the compiler command line. However: there are a couple of other special stipulations that also have to be made to the compiler, and also a little postprocessing/tidying up to be done after the compilation. Therefore, safe-c is accompanied by a small batch file called scc.bat. A batch file is simply a text file containing a series of DOS commands, to be executed in sequence. So, if your file is called, say, hello.c, then the command:

    scc hello

will actually cause a whole series of commands in scc.bat to be executed. These will automatically invoke the compiler in the correct way to incorporate the safe-c object file into the executable file.

However: note that scc.bat is only appropriate for compiling programs which make use of safe-c. When you progress to the point of directly using the standard C library, then you must also learn how to directly invoke the compiler in the appropriate way, rather than relying on scc.bat to do it.




Document: The safe-c User Guide

next Overview
up The safe-c User Guide
gif What is a Module anyway?



McMullin@eeng.dcu.ie
Fri Jan 12 12:30:02 GMT 1996