Why am I unable to #ifdef stdafx.h?
Asked Answered
M

2

12

I am trying to include 2 platform-specific stdafx.h files in my .cpp file, but the compiler is unhappy when I try to #ifdef it.

#ifdef _WIN32
#include "stdafx.h"
#elif _MAC
#include "MAC/stdafx.h"
#endif

You may wonder why I am using stdafx.h in the Mac code, but that is not important at the moment :).

When I try to compile the code on Windows, I receive: Fatal Error C1018. I tried enclosing other header files with #ifdef in the same file, and the compiler was happy. Therefore, it looks like Windows doesn't like stdafx.h to be #ifdef-ed, or that Windows only allows #include stdafx.h to be the first line in the file.

So my question is, why?

Kat

Mcarthur answered 16/9, 2009 at 22:18 Comment(0)
S
10

When the compiler includes a pre-compiled header, it basically "forgets" anything that came before the header. Thus your #elif isn't matched to a #if anymore.

Suspect answered 16/9, 2009 at 22:24 Comment(0)
T
6

This is because you have Precompiled Headers turned on - turn it off and you should be fine.

Teamwork answered 16/9, 2009 at 22:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.