-Pio: Include Files Only Once

Group

INPUT

Scope

Compilation Unit

Syntax
  -Pio
  
  
Arguments

None

Default

None

Defines

None

Pragmas

None

Description

Includes every header file only once. Whenever the compiler reaches an #include directive, it checks if this file to be included was already read. If so, the compiler ignores the #include directive. It is common practice to protect header files from multiple inclusion by conditional compilation, as shown in the following listing:

Listing: Conditional compilation


/* Header file myfile.h */

#ifndef _MY_FILE_H_

#define _MY_FILE_H_

/* ... content ... */

#endif /* _MY_FILE_H_ */

When the #ifndef and #define directives are issued, any header file content is read only once even when the header file is included several times. This solves many problems as C-language protocol does not allow you to define structures (such as enums or typedefs) more than once.

When all header files are protected in this manner, this option can safely accelerate the compilation.

This option must not be used when a header file must be included twice, e.g., the file contains macros which are set differently at the different inclusion times. In those instances, #pragma ONCE: Include Once is used to accelerate the inclusion of safe header files that do not contain macros of that nature.

Example

-Pio