Programming Guidelines

1. Definitions

We have three levels of components. The higher one is a package (currently, the choice is MRC or CIS). Each package is a set of modules (e.g. in CIS, we have Vecs, Common, etc.). Each module corresponds to a library or DLL and is usually prefixed with the package name in lower case(e.g. cisCommon, cisVecs, etc.). Finally, the lowest level is a file.

For all examples, code and file names are displayed as html code font. File name example cisThisIsMyFile.h and code example int myVariable;.

For a reference on how to document erc libraries using doxygen; please see the How to document code using Doxygen page.

2. Naming

2.a. File names and content

2.b. Classes, Methods, Data Members, Arguments, Variables and Macros

These recommendations must really be respected for classes, methods and data members (at least the public and protected ones) since they are part of the interface. To summarize, every global element is prefixed with the package name in lower case. These rules should help any programmer to quickly determine the nature of an element:

3. Formatting

3.a. Instructions

3.b. Blocks of instructions

4. Portability

5. Other recommendations

6. Operating System and Compiler

6.1. Windows DLL

To compile a Dll (Dynamic link library) for Windows with Visual C++, it is necessary to add some code in the header files. Since this code depends on the operating system and the compiler, we use macros. These macros are null for most cases, including all unix like operating systems and when compiling static libraries for Windows.

For Dlls, we have two cases which are either an import (use _declspec(dllimport)) or an export (use _declspec(dllexport)) and both cases can occur for the same header file. For example, a symbol defined in file1.h should be exported by the Dll file1.dll which contains the object code of file1.obj compiled from file1.cpp (which includes file1.h, who's lost?). But the same symbol is imported when compiling a program or a Dll relying on symbols defined in file1.h. So, the macro definition is based on the context and there must be an external flag (preprocessor defined variable) which tells us if we are using some Dlls or compiling a specific Dll.

For a program using some Dll, it is necessary to define CIS_DLL so that all included header files use _declspec(dllimport). For the compilation of a Dll we need to set CIS_DLL_<MODULE> (e.g. for CISVecs, set CIS_DLL_VECS). Each module (equivalent to library or Dll) must have its own file to defines the import/export macros. This file is named <PACKAGE><Module>Export.h (e.g. CISVecsExport.h).

Once this file is created, every header file which contains symbol to export should include it. This inclusion defines the following macros:

6.2. Irix


Last modified: Wed Sep 19 14:21:43 EDT 2001