INF: Using Preprocessor Directives to Identify the Platform

PSS ID Number: Q102785
Article last modified on 01-12-1994

2.50    | 2.50
WINDOWS | MS-DOS

--------------------------------------------------------------------
The information in this article applies to:

 - Microsoft FoxPro for Windows, version 2.5
 - Microsoft FoxPro for MS-DOS, version 2.5
--------------------------------------------------------------------

SUMMARY
=======
Preprocessor directives can make use of constants and any FoxPro
function that does not reference variables or database fields.
Preprocessor directives cannot make use of user variables or system
variables, such as those used to identify the system platform.
By using constants with preprocessor directives, you can compile only
the code that applies to a specific platform, or you can create a
program that checks to see what platform it was compiled under and
then acts appropriately. See below for examples.

MORE INFORMATION
================
The system variables _DOS, _WINDOWS, _MAC, _UNIX are run-time
variables. They are designed to allow the creation of a program that
will run differently on different platforms. For example:
   DO CASE
   CASE _DOS
      ? "this program is running under DOS"
   CASE _WINDOWS
      ? "this program is running under Windows"
   ENDCASE
Preprocessor directives are evaluated at compile time. To only compile
code that applies to a specific platform, you can define a constant.
The compiler directives can then reference this constant as follows:
   #DEFINE platform 'DOS'
   #IF platform = 'DOS'
      ? "this program was compiled under DOS"
   #ELIF platform = 'WINDOWS'
      ? "this program was compiled under Windows"
   #ENDIF
The above program will always display, "this program was compiled
under DOS" even if it is compiled and run by FoxPro for Windows. To
limit compilation of the above program to only the code intended for
FoxPro for Windows, simply change the first line to:
   #DEFINE platform 'WINDOWS'
You can also use this technique to make a program smart enough to
check what platform it is compiled under and act appropriately. For
example:
#DEFINE mvers version()
#IF 'DOS' $ upper(mvers)
   ? 'compiled in DOS'
#ELIF 'WIN' $ upper(mvers)
   ? 'compiled in Windows'
#ENDIF
If the above program is compiled under FoxPro for MS-DOS, it will
always display "this program was compiled under DOS", even if it is
run under FoxPro for Windows.
Additional reference words: 2.50 Preprocessor #IF System Variables
_DOS _WINDOWS _MAC _UNIX Run-time compile-time

Copyright Microsoft Corporation 1994.