Skip to content

Use of Common Headers

LIU Hao edited this page Jul 25, 2023 · 5 revisions

There are three types of common headers:

fwd.h

The forward declarations header

  • brings simple standard types, such as size_t and int32_t, by including <stddef.h> and <stdint.h>, respectively.
  • declares inline functions and macros that are utilized by other headers, such as max().
  • should be included as the first header by other headers.
  • provides forward declarations for everything from the same project.

utils.h

The general utilities header

  • brings complex standard types, such as std::ostream, by including <ostream>.
  • declares functions that are commonly used by all source files.
  • shall not be included by other headers from the same project.
  • should be included as the last header by other source files.

precompiled.h

The pre-compiled header

  • includes many potential dependencies, such as <vector> and <algorithm>.
  • shall not be included by any headers.
  • should be included as the first header by all source files.