stdafx.h
is the idiomatic name used for precompiled headers in the Visual Studio ecosystem. In a nutshell, it's a regular header, but the contents of this file will be compiled once and reused for all cpp files in the project.
That is useful since in most projects, a large number of headers (standard library, system header, shared project-wide definitions) are used by virtually all translation units (cpps), so using PCH is a huge performance benefit during compilation
(Actually, PCH is a hack to workaround C++' inefficient compilation and linkage model and it's a shame that we need to maintain it by hand … oups, blasphemy.)
But this also means that - as long as the contents of your stdafx.h
are gcc-compatible - compilation with CodeBlocks should still work, but without the immediate performance benefit.
The stdafx.h
generated by VS' app wizards doesn't work out of the box on other platforms - it typically includes Windows.h
. So to make it work, guard the Windows-specific definitions with appropriate #ifdef/#endif
pairs and vice versa for Linux or Mac-specific stuff.