1

I found a project with this structure:

// Header.h
#ifndef HEADER_H
#define HEADER_H
...
#endif

// Source.cpp
#ifndef HEADER_H
#include "Header.h"
#endif

To me, this seems to be a bit redundant.

Maybe there could be a small performance improvement during the build, due to the fact that the compiler does not need to open the include file to realize it can ignore it. But I think today's compilers have better ways to optimize such things.

Am I wrong?

Pietro
  • 12,086
  • 26
  • 100
  • 193
  • 1
    Modern compilers do not re-open files to check for include guards. In olden times they did, and `#pragma once` was a non-standard optimization to make the process more effective, but compilers have improved since (and we're talking about 20 years since `#pragma once` became unnecessary). I smell a naive attempt at optimization. (Not that I didn't do that myself at some point. ;-) ) – DevSolar Apr 16 '15 at 09:36
  • 1
    Plus one but don't do this. It's yet another include guard name to remember to change but this time in a thoroughly unexpected place. – Bathsheba Apr 16 '15 at 09:39

0 Answers0