KnowledgeBase Archive

An Archive of Early Microsoft KnowledgeBase Articles

View on GitHub

Q44927: How Does _osmode Get Set?

Article: Q44927
Product(s): See article
Version(s): 5.10   | 5.10
Operating System(s): MS-DOS | OS/2
Keyword(s): ENDUSER | SR# G890523-18896 | mspl13_c
Last Modified: 21-AUG-1989

The Microsoft C Run-time Library variable _osmode is set to one (1)
when running under OS/2 and to zero (0) when running under DOS. A C
program can look at this variable and easily determine whether it's
running under DOS or OS/2, without calling DosGetMachineMode.

To declare the variable, use the following line:

   #include <stdlib.h>

An examination of the start-up code (included with the compiler) shows
how the value of this variable is determined. The DOS start-up 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 DOS or one for OS/2. Thus, you don't need to make the call.

If you compile for DOS (/Lr or /Lc), the DOS start-up code is included
because the linker links your program with the appropriate 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.

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.

Copyright Microsoft Corporation 1986-2002.