CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 1999
    Posts
    1

    #ifdef's and #include's

    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.


  2. #2
    Join Date
    May 1999
    Location
    Oregon, USA
    Posts
    302

    Re: #ifdef's and #include's

    I can't see anything wrong with what you have posted.
    Maybe there is a problem in one of the other header files.



  3. #3
    Join Date
    May 1999
    Location
    Mangalore, Karnataka, India
    Posts
    21

    Re: #ifdef's and #include's

    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

  4. #4
    Join Date
    May 1999
    Location
    WA
    Posts
    236

    Re: #ifdef's and #include's

    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

  5. #5
    Guest

    Re: #ifdef's and #include's

    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


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured