Rules for straight ANSI C:

Assumptions

Object oriented programming classes are not supported.

A program

A program's executable code is made up of

Source code files

For maintenance, the source code is written as:

Simulating Modules with include files

We try to simulate modules with include files. As stated above, the source of a module consists of: The ".h" file is included by other modules, which must see the variable as extern during their compilation. The exporting module also needs the declarations, but without the "extern" keyword. Therefore either the declarations occur again inside the module's ".c" file or we find a mechanism of re-using the ".h" file. Writing the declarations twice means a maintenance problem when changes happen.

The following mechanism is proposed for including ".h" files:

#include <Importation.d> in order to define "PROVIDE" to be either null or "extern" depending on whether the word "IMPORT" is defined. INITIALLY(initial value); (no equal sign!). Example for initialising exported integer i to 5: PROVIDE int i INITIALLY(5); The file Importation.d contains: #undef PROVIDE #ifdef IMPORT #define PROVIDE extern #define INITIALLY(s) #else #define PROVIDE #define INITIALLY(s) = s #endif Thus, in a module A which imports from a module B, the ".c" file starts with: #define IMPORT #include "B.h" ... #undef IMPORT But module B's ".c" file has the line #include "B.h" outside of "#define IMPORT" / "#undef IMPORT" brackets.

The ".h" file of a module never imports from other modules (but it can of course use #include for definitions).

Global variables

Because they are instantiated as code, they are written as a module.

Because there are only variables, the ".h" file contains all the declarations and the ".c" file is empty apart from an include for generation of the code. The ".c" file is simply:

#include "Globals.h"

The Main routine

The main routine's ".c" file looks like: #include <... .h> #include <... .h> #define IMPORT #include "Definitions.d" #include "Globals.h" #include "A.h" #include "B.h" #include "... ".h"" #undef IMPORT void main() { ... ... }

RC