INF: How to Set _osmode

ID Number: Q44927

5.10 6.00 6.00a 6.00ax | 5.10 6.00 6.00a

MS-DOS | OS/2

Summary:

In Microsoft C versions 5.0, 5.1, 6.0, 6.0a, and 6.0ax, the C run-time

library variable _osmode is set to one (1) when running under OS/2 and

to zero (0) when running under MS-DOS. A C program can look at this

variable and easily determine whether it's running under MS-DOS or

OS/2, without calling DosGetMachineMode. With C 6.0, there are two

predefined constants that can be used to check the _osmode. They are

DOS_MODE, which is zero (0), and OS2_MODE, which is one (1).

To declare the variable, use the following line:

#include <stdlib.h>

More Information:

An examination of the startup code (included with the compiler) shows

how the value of this variable is determined. The MS-DOS startup code

just initializes the variable to zero. The OS/2 code initializes it by

making a call to the OS/2 API DosGetMachineMode, which sets it to zero

for MS-DOS or one for OS/2. Thus, you don't need to make the call.

If you compile for MS-DOS (/Lr or /Lc), the MS-DOS startup code is

included because the linker links your program with the appropriate

MS-DOS library (xLIBCyR, where x is the memory model and y is the math

option). By the same token, when you compile with /Lp, the linker

links the proper library for OS/2 (xLIBCyP). If you don't specify one

of these options, your code is linked with xLIBCy.

Additional reference words: 5.00 5.10 6.00 6.00a 6.00ax