KnowledgeBase Archive

An Archive of Early Microsoft KnowledgeBase Articles

View on GitHub

Q44009: C2097 Attempt to Initialize Short Address with Long Address

Article: Q44009
Product(s): See article
Version(s): 1.01 1.00
Operating System(s): MS-DOS
Keyword(s): ENDUSER | | mspl13_c
Last Modified: 2-MAY-1989

When the example below is compiled in the medium memory model, the
compiler returns the following error message:

   C2097  illegal initialization

The following description of this error, which can be found on Page
261 of the "Microsoft C Optimizing Compiler User's Guide" and on Page
331 of the "Microsoft QuickC Programmer's Guide," is incomplete:

   An attempt was made to initialize a variable using a non-constant
   value

Attempting to initialize a short address with a long address is
another type of illegal initialization that can return this error.

The example below demonstrates the problem when compiled in the medium
memory model. The medium memory model is the only memory model
available in Versions 1.00 and 1.01 of the QuickC environment. QuickC
2.00 and the Microsoft C Optimizing Compiler support five memory
models. QuickC 1.00 and 1.01 support four memory models (no huge) when
compiling outside of the environment.

To prevent the problem, compile with either /AS, /AL, or /AH (the
small, large, or huge memory model, respectively). This ensures that
the addresses for data are the same size as the addresses for code.
Alternatively, make appropriate casts when initializing pointers and
specify the far keyword on declarations as necessary.

To compile (but not link) for small model with QuickC, use the
following command line:

   qcl /AS /c test.c

Or, with the Microsoft C Optimizing Compiler, use the following
command line:

   cl /AS /c test.c

The code example is as follows:

/*  example  */

int exit();

typedef struct { void * data;
               } selection;

selection menu[] = { { 0 },            /*  data  */
                     { exit }          /*  code  */
                   };

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.