Determining the Memory Model for Conditional Compilation

Last reviewed: July 17, 1997
Article ID: Q44386
6.00 6.00a 6.00ax 7.00 | 6.00 6.00a | 1.00 1.50
MS-DOS                 | OS/2       | WINDOWS
kbtool

The information in this article applies to:

   The Microsoft C/C++ Compiler (CL.EXE) included with:
    - Microsoft C for MS-DOS, versions 6.0, 6.0a, and 6.0ax
    - Microsoft C for OS/2, versions 6.0, and 6.0a
    - Microsoft C/C++ for MS-DOS, versions 7.0
    - Microsoft Visual C++ for Windows, versions 1.0 and 1.5

SUMMARY

There is a predefined identifier that can be used to allow the preprocessor to determine which memory model has been chosen for the current compilation. The identifier is M_I86?M, where "?" is an identifier for one of the following five memory models:

   S = Small
   M = Medium
   L = Large
   C = Compact
   H = Huge

This identifier can be used with a preprocessor command to produce conditional compilation dependent upon the memory model. An example of its use is shown below.

Sample Code

/* Compile options needed: none
*/

/*
 *
 * This example demonstrates how to use the C compiler M_I86?M values.
 * It also shows other various preprocessor components. The memory
 * model is displayed using the message() pragma. If the memory model
 * is not recognized by the program, the compilation terminates using
 * the #error preprocessor directive. The identifier _MEMORY_MODEL_
 * has been chosen arbitrarily, and has no special value to the C
 * compiler.
 *
 */

#include <stdio.h>

#if defined (M_I86CM)
    #define _MEMORY_MODEL_ "compact"
#elif defined (M_I86SM)
    #define _MEMORY_MODEL_ "small"
#elif defined (M_I86MM)
    #define _MEMORY_MODEL_ "medium"
#elif defined (M_I86HM)
    #define _MEMORY_MODEL_ "huge"
#elif defined (M_I86LM)
    #define _MEMORY_MODEL_ "large"
#else
    #error "ERROR: unknown memory model!!"
    #define _MEMORY_MODEL_ "**UNKNOWN**"
#endif

#pragma message ("Using the " _MEMORY_MODEL_ " memory model...")

void main(void);

void main(void)
{
   printf("hello, world\n");
}


Additional reference words: kbinf 1.00 1.50 6.00 6.00a 6.00ax 7.00 8.00
8.00c
KBCategory: kbtool
KBSubcategory: CLIss
Keywords : kb16bitonly


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: July 17, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.