Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

#ifndef

Status
Not open for further replies.

Pyramus

Programmer
Dec 19, 2001
237
GB
#ifndef _TESTHARNESS
#include "stdafx.h"
#endif

What the hells wrong with this? I get unexpected endif errors.
 
I think that you dont need to put an "#endif" here,maybe because there is already one at the end of "stdafx.h".
 
That seems a bit weird. If stdafx.h had an extra #endif you shouldnt be able to compile. In the file you are working in, check ALL the includes to make sure they have matching #ifdefs and #endifs Just because you are getting the error in this particular file, it does not mean that the actual culprit of the unmatching #endif exists in the writing verbatim what is in the include file in place of the #include statment. For Example

//********* FILE ex.h *************
#ifdef EX_H
#define EX_H
#include "abc.h"
#endif
#endif // notice the extra endif
//******* END OF EX.h ************

//******** OTHER FILE other.h *****
#ifdef OTHER
#define OTHER
#include "ex.h"
#endif
//***********************************

In this case the file other.h will give the error for an un matching endif (If i remember correctly). All I really remember is I have seen this before and the error didnt really exist in the file the compiler said it did. Also, you can compile to just the preprocessor and see what it looks like. I forget the code for this but it is in the VC++ documentation.

Matt

 
I didn't actually meant that there was an extra "#endif" at the end of the file "stdafx.h" but still it is difficult to explain why there is an error occuring when puting and "#endif" after those lines:

#ifndef _TESTHARNESS
#include "stdafx.h"

I have try it myself and there was the same problem.
The only way out of this is to not put any "#endif" after the two previous line of code.
 
VC++ treats stdafx.h in a weird way, depending on your project settings. Make sure your project is highlighted then hit Alt+F7 to bring up your project settings. In the C/C++ tab, use the combo box to go to "Precompiled Headers".

Basically, if you are using precompiled headers and "stdafx.h" is NOT included in a .cpp file, the .cpp file will produce lots of weird errors... most commonly, it won't find the end of the file.

Try putting your
Code:
#ifndef _TESTHARNESS
in "stdafx.h" instead, maybe?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top