Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 243
Virus721 Avatar asked Jul 22 '16 08:07

Virus721


People also ask

What does word unexpected mean?

Definition of unexpected : not expected : unforeseen.

What is an example of unexpected?

Examples from Collins dictionariesHis death was totally unexpected. He made a brief, unexpected appearance at the office. Help may also come from some unexpected places.

How would you describe something unexpected?

In this page you can discover 50 synonyms, antonyms, idiomatic expressions, and related words for unexpected, like: unpredicted, unforeseen, unanticipated, sudden, like a bolt from the blue, unprepared for, serendipity, not on the books, amazing, uncontemplated and aleatory.


1 Answers

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.

like image 149
Dutow Avatar answered Sep 20 '22 22:09

Dutow