BUG: #IF <System Memvar> Returns "Invalid Preprocessor..."

ID: Q115953

2.50 2.50a 2.50b 2.60 | 2.50 2.50a 2.50b 2.60 | 2.50b 2.50c

WINDOWS               | MS-DOS                | MACINTOSH

The information in this article applies to:

SYMPTOMS

The compiler directives #IF ... #ENDIF used with the _DOS, _WINDOWS, _MAC, and _UNIX system memory variables generate an "Invalid preprocessor expression" error message when compiled under FoxPro for Windows and FoxPro for Macintosh. FoxPro for MS-DOS does not produce any error messages when the same code is compiled. Instead, it compiles the statement following #IF _DOS and displays "This displays only when running under DOS".

RESOLUTION

To obtain the desired results when using preprocessor directives, run the following code in all three products:

   #IF 'WINDOWS' $ UPPER(VERSION())
            ? "This should display only when running under Windows"
   #ELIF 'MAC' $ UPPER(VERSION())
        ? "This should display only when running on the Macintosh"
   #ELSE
        ? "This should display only when running under DOS"
   #ENDIF

STATUS

Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

Both FoxPro for Windows and Macintosh return the expected results because the _DOS, _WINDOWS, _MAC, and _UNIX system memory variables are not considered preprocessor definitions since they are evaluated at run time, not compile time.

The online help system for FoxPro for Windows, MS-DOS, and Macintosh contains the following warning:

NOTE: Do not use system memory variables for <expN1> or <expL1>. System memory variables are not evaluated until run time.

Steps to Reproduce Problem

1. Load FoxPro for Windows and run the following program:

      #IF _WINDOWS
             ? "This displays only when running under Windows"
      #ENDIF

      #IF _MAC
            ? "This displays only when running on the Macintosh"
      #ENDIF

      #IF _DOS
           ? "This displays only when running under DOS"
      #ENDIF

2. Issue the MODIFY FILE <filename.ERR> command. Note that there are three
   compile errors (for example, "Invalid preprocessor expression") listed
   in the .ERR file. Close FoxPro for Windows.

3. Load FoxPro for MS-DOS and run the same program. Make sure that the .FXP
   file does exist before you issue the DO <filename.prg> command. This
   will ensure that FoxPro for MS-DOS will recompile the program.

FoxPro for MS-DOS will display the following message:

   This displays only when running under DOS

Additional reference words: FoxMac FoxDos FoxWin 2.50 2.50a 2.50b 2.60 2.50c buglist2.50 buglist2.50a buglist2.50b buglist2.60 buglist2.50c memvar KBCategory: KBSubcategory: FxenvMemory
Keywords          : kberrmsg FxenvMemory 
Version           : 2.50 2.50a 2.50b 2.60 | 2.50 2.5
Platform          : MACINTOSH MS-DOS WINDOWS

Last Reviewed: May 22, 1998