Virus721
Virus721

Reputation: 8335

Unexpected #else

For some reason I can't explain, the compiler is outputting an error saying that it found an unexpected #else token.

This occurs at the beginning of the file :

#if defined( _USING_MFC )
   #include "stdafx.h"
#else
   #include <windows.h>
#endif

There is nothing before that peice of code expect several (single-line) comments.

This error occurs in a .cpp file. What you see above is the beginning of the file. There is nothing before that.

I tried adding the following code before the code defined above, and the error is now an unexpected #endif

#if 1
   #include "stdafx.h"
#endif

So I suspect there is an issue with the included stdafx.h file which contains the following code :

#ifndef STDAFX_H_INCLUDED
#define STDAFX_H_INCLUDED

#include <Afx.h>
#include <Windows.h>

using namespace ATL;

#endif // STDAFX_H_INCLUDED

There's really nothing special about it. I'm also including this stdafx.h file from a stdafx.cpp file that only contains the #include statement, and it compiles correctly.

Here are the project preprocessor definitions :

_DEBUG
_WIN32_WCE=$(CEVER)
UNDER_CE
WINCE
DEBUG
_WINDOWS
$(ARCHFAM)
$(_ARCHFAM_)
_UNICODE
UNICODE
_TERMINAL_FALCONX3_CE6
_NO_CPP_EXCEPTIONS
_DONT_INCLUDE_WS_HEADERS
_USING_MFC

And some extra informations : Compiling for Windows CE 6 using Visual Studio 2008.

What would be causing this ? Thank you.

Upvotes: 8

Views: 1201

Answers (1)

Dutow
Dutow

Reputation: 5668

Based on the name stdafx, I assume it is a precompiled header.

A precompiler header must be the first include (preprocessor) directive in the file, you can't put anything (not even an ifdef) before it. The only exception being a few comment lines, as those would be ignore anyway.

Based on your example, you should put the #ifdef _USING_MFC into your stdafx.h, and include Afx.h there.

Upvotes: 11

Related Questions