Preprocessor Directives Incorrect in "Language Tips" Help

Last reviewed: June 27, 1995
Article ID: Q118617
The information in this article applies to:
  • Microsoft FoxPro for Windows, versions 2.5, 2.5a, 2.5b, 2.6
  • Microsoft FoxPro for MS-DOS, versions 2.5, 2.5a, 2.5b, 2.6
  • Microsoft FoxPro for Macintosh, versions 2.5b, 2.5c

In the "Language Tips" section of the online Help file, under the "Tips and Tricks" topic, the second paragraph under the "Preprocessor Directives" topic incorrectly states the following:

   This code would not work because _DOS would be changed to .T. and
   _WINDOWS would be changed to .F. so that the code could never work
   properly again. Instead use the following:

      #IF "Win" $ VERS()
      #DEFINE windows_code .T.
      #ELIF "Mac" $ VERS()
      #DEFINE mac_code .T.
      #ELIF "Unix" $ VERS()
      #DEFINE unix_code .T.
      #ELSE
      #DEFINE dos_code .T.
      #ENDIF
      #IF windows_code
      ? "Compiled under WINDOWS"
      #ELIF dos_code
      ? "Compiled under DOS"
      #ENDIF

This resolution code is incorrect because FoxPro does not allow nested preprocessor directives. When you compile the code above, it will create an .ERR file with the same name as the source file if the .ERR File option is selected in the Compile dialog box. The *.ERR file will log the following errors:

   #elif "Mac" $ VERS()
   Error in line 3: Mismatched #if/#elif/#else/#endif.
   #elif "Unix" $ VERS()
   Error in line 5: Mismatched #if/#elif/#else/#endif.
   #else
   Error in line 7: Mismatched #if/#elif/#else/#endif.
   #endif
   Error in line 9: Mismatched #if/#elif/#else/#endif.

The correct resolution code is:

   #DEFINE win_code "Win" $ VERS()
   #DEFINE mac_code "Mac" $ VERS()
   #DEFINE unix_code "Unix" $ VERS()
   #DEFINE dos_code NOT("Win" $ VERS() OR "Mac" $ VERS() ;
      OR "Unix" $ VERS()))
   #IF win_code
   ? "Compiled under WINDOWS"
   #ELIF dos_code
   ? "Compiled under DOS"
   #ENDIF


Additional reference words: FoxMac FoxDos FoxWin 2.50 2.50a 2.50b 2.50b
2.60
docerr
KBCategory: kbprg kbdocerr
KBSubcategory: FxprgGeneral


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: June 27, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.