Integer Input and Output

Chapter 14 - Advanced Programming Topics

Visual C++ 6: The Complete Reference
Chris H. Pappas and William H. Murray, III
  Copyright 1998 The McGraw-Hill Companies

Making Header Files More Efficient
The compiling of header files is made more efficient by using combinations of preprocessor directives. The best way to learn how to construct an efficient header file is to look at an example:
#ifndef _INC_IOSTREAM
#define _INC_IOSTREAM

#if !defined(_INC_DEFS )
#include <_defs.h>
#endif

#if !defined(_INC_MEM )
#include <mem.h>    // to get memcpy and NULL
#endif
#endif  /* !_INC_IOSTREAM */
Before looking at the individual statements in the example, you need to know that passing one of the compiler builds a symbol table. One of the entry types in a symbol table is the mangled names of header files. Mangling is something that the compiler does to distinguish one symbol from another. The C compiler prepends an underscore to these symbols.
The easiest way to control the compiled visibility of a header file is to surround the code within the header file with a tri-statement combination in the form:
#ifndef _INC_MYHEADER
#define _INC_MYHEADER
  /* begin _INC_MYHEADER visibility */
    .
    .
    .
#endif /* end of conditional _INC_MYHEADER visibility */
This is exactly what was done with the previous coded example where _INC_IOSTREAM was substituted for _INC_MYHEADER. The first time the compiler includes this header file, _INC_IOSTREAM is undefined. The code segment is included, making all of the nested statements visible. From this point forward, any additional #include <iostream.h> statements found in any of the other files used to create the executable bypass the nested code.

Books24x7.com, Inc 2000 –  


Visual C++ 6(c) The Complete Reference
Visual Studio 6: The Complete Reference
ISBN: B00007FYGA
EAN: N/A
Year: 1998
Pages: 207

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net