Click to See Complete Forum and Search --> : #ifdef's and #include's


Vaughan Daniel
July 16th, 1999, 11:33 AM
Can someone please explain to me why you can't have #include statements within a #ifdef #else # endif conditional structure in Microsoft C++ ver. 6.0?

example:
#ifdef LEGACY_CODE
#include "first.h"
#include "second.h"
#else
#include "third.h"
#include "fourth.h"
#endif

The compiler gives the error 'fatal error C1020: unexpected #else'.

This is the first time I attempted to do this so I am not sure if this is just MS compilers or all C++ compilers in general.

Gomez Addams
July 16th, 1999, 12:08 PM
I can't see anything wrong with what you have posted.
Maybe there is a problem in one of the other header files.

Srinidhi
July 17th, 1999, 06:20 AM
Hi
There is nothing wrong there. Please check out ur code one. It may be giving that problem due to some other bug.

Srini.


Srinidhi Rao

herbieII
July 17th, 1999, 08:02 AM
Are the 4 header files in your project? If not that might be what is causing the error. I have used conditional assemblies like this with NO errors.

Roger L. McElfresh

July 17th, 1999, 11:27 AM
I'm pity to tell you I suppose your header file: first.h or second.h, maybe some nest error.
And, I can almost ensure that error is in second.h.
So, check the header file, to ensure it's no any error, just like:
#ifndef __second_h
#define __second_h
//...
#endif//__second_h
#endif//ERROR!
//END OF FILE


Notice that no matched #ifdef above it.
So, good lucky!

FlyingYe