Getting Started | Documentation | Glish | Learn More | Programming | Contact Us |
Version 1.9 Build 1556 |
|
\#if !defined(AIPS\_H\_) \#define AIPS\_H\_ BODY OF INCLUDE FILE \#endif
Header files should not initialize values. The user of a given header file should be assured that including the header file will not increase the object-code size. This practice forces the data to be owned by a given source file, and avoids complicated initialization constructs in the header files. (See p.154 Plum)
Another example of preprocessor utility is the ## operator for concatenation of tokens. This has no equivalent operation in C++. In addition, #ifdefs also provide the only reasonable means of conditional compilation. e.g.
\#if defined(\_\_cplusplus) C++ CODE \#elif defined(\_\_STDC\_\_) ANSI C CODE \#else K\&R C CODE \#endif
With the exception of include file protection, preprocessor functions should be used with caution. The ## operator, for example, is not available on K&R C compilers. The typical work around is to define a macro which uses an empty comment, /**/, for concatenation. Careless ifdefs for conditional compilation throughout code make it difficult to maintain.
When the preprocessor is utilized macro or defines which begin with a double underscore, ``__'', or single underscore, ``_'', should be avoided because are used by C and C++.
\#define \_lib\_aips(name) aips\#\#namewhich will create a token unique to the aips project. This will be generated by sed/egrep which will pull out class definitions and generate the defines for the class name. So a define will be generated for each class name, #define MyClass _lib_aips(MyClass). Thus aips scope can be entered by including a given file, aips-enter.h, and aips scope can be exited by including a different file, aips-exit.h.
Thus to enter an AIPS++ code section the programmer would include the file aips-enter.h and this file would be automatically generated from the other AIPS++ header files and might look like:
// No multiple inclusion protection to allow reentering AIPS++ // scope in the same file, file contains only \#defines. \#define String \_lib\_aips(String) ...MORE SIMILAR DEFINES...Thus every time a developer referenced a member of class String the class name would be replaced with _lib_aips(String) which would expand as described above to aips##String and finally to aipsString. Then to exit the scope of aips code the developer would include file aips-exit.h which is also automatically generated. This file might look like:
\#undef String ...MORE SIMILAR UNDEFS...Thus each reference to String would now reference a string defined possibly in some other class library. Hopefully, this sort of context switching will be the exception rather that the rule, and developers will simply include aips_enter.h at the top of a source file and not have to worry about name clashes.
In addition, the use of identifiers which begin with a double underscore, ``__'', or a single-underscore, ``_'', should be avoided. Identifiers which begin with a double underscore are reserved for C++ and those which begin with a single underscore are reserved for C.