Do C++ Compilers Repeatedly Process the Same Header Files?

  • Context: C/C++ 
  • Thread starter Thread starter Chromium
  • Start date Start date
  • Tags Tags
    C++
Click For Summary

Discussion Overview

The discussion revolves around whether C++ compilers repeatedly process the same header files during compilation, particularly in the context of multiple .cpp files including the same .h files. The scope includes technical explanations and potential compiler optimizations.

Discussion Character

  • Technical explanation, Debate/contested

Main Points Raised

  • One participant asserts that C++ compilers compile the same .h files multiple times when processing different .cpp files.
  • Another participant counters that some compilers, specifically Visual compilers, utilize precompiled headers to optimize compilation time and resource usage.
  • A later reply questions the necessity of precompiled headers and suggests that the ability to enable or disable this feature may depend on the specific compiler being used.
  • One participant confirms that the feature can be toggled on or off as desired.

Areas of Agreement / Disagreement

Participants express differing views on the behavior of C++ compilers regarding header file processing, with some supporting the idea of repeated processing and others advocating for the use of precompiled headers as a solution. The discussion remains unresolved regarding the extent to which compilers handle header files consistently.

Chromium
Messages
56
Reaction score
0
Is it true that most, if not all, C++ compilers tend to compile the same .h files over and over again? Say there are two .cpp files that include the same .h file, and the compiler processes one of these .cpp files & all its included header files as well. Once it gets to the second .cpp file, it doesn't recognize that it has seen the one .h file before, and so it just processes that file again, right?
 
Technology news on Phys.org
Not necesarrilly. Visual compilers (Microsoft) prepare something they call precompiled header to save on resources/compilation time. I suppose other compilers are able to do the same.
 
Oh, I see. Although I guess it makes more sense to use precompiled headers, isn't it possible to turn that feature off (I guess it depends on the compiler)?
 
On/off, as you wish.
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
3K
Replies
6
Views
2K
Replies
4
Views
5K
Replies
81
Views
8K
  • · Replies 27 ·
Replies
27
Views
6K
Replies
65
Views
5K
Replies
6
Views
3K
  • · Replies 7 ·
Replies
7
Views
14K
  • · Replies 75 ·
3
Replies
75
Views
7K
  • · Replies 14 ·
Replies
14
Views
5K