c++visual-studio-2010precompiled-headers

Why are header guards unnecessary in stdafx.h?


I don't understand why header guards are not used in pre-compiled headers... Any ideas?


Solution

  • Usually, stdafx.h will be included only once per cpp file, as the first statement, and normally, no other files will include it. So, chances of recursively including stdafx.h are minimal, thus the "unnecessariness" of the include guard.

    I would still advise to use one, just in case, or potentially use #pragma once at the top of the file.