PRB: C4058 Generated with /ASu, /ASw, /AMu, and /AMw

Last reviewed: July 17, 1997
Article ID: Q37632
6.00 6.00a 6.00ax 7.00 | 6.00 6.00a | 1.00 1.50
MS-DOS                 | OS/2       | WINDOWS
kbtool kbprb 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, version 7.0
    - Microsoft Visual C++ for Windows, versions 1.0 and 1.5

SYMPTOMS

An attempt to pass the address of a local variable to a function that expects a pointer fails when the compiler options include /ASu, /ASw, /AMu, or /AMw. C versions 6.x generate the following message:

   C4058: address of automatic (local) variable taken, DS != SS

C/C++ version 7.0 generates the following message:

   C4762: near/far mismatch in argument; conversion supplied

In C/C++ versions 8.0 and 8.0c, the message depends on the option selected. If the command line includes /ASw or /AMw, the compiler produces the following messages:

   C4758: address of automatic (local) variable taken, DS != SS
   C4762: near/far mismatch in argument : conversion supplied

If the command line includes /ASu or /AMu, the compiler produces the following message:

   C4762: near/far mismatch in argument : conversion supplied

CAUSE

The segment setup codes "u" and "w" inform the compiler that the stack segment (SS) and the data segment (DS) are not necessarily identical. In the small and medium memory models, data pointers are assumed to be near (in DS) and local variables are stored on the stack (in SS). The warnings occur because DS and SS may not be equal.

RESOLUTION

To eliminate the warning, perform one of the following:

  • Declare the local variable with the "static" attribute.
  • Declare the function to receive a _far pointer parameter.
  • Compile the code with the compact or large memory model. However, this option may have other implications for your code.

MORE INFORMATION

The following sample code illustrates the situation:

Sample Code

/*
 * Compile options needed: /AMw
 */

void inc(int *);

void main(void)
{
   int p = 666;
   inc(&p);               /* address of stack variable */
}

void inc(int *p)
{
   (*p)++;
}


Additional reference words: 1.00 1.50 6.00 6.00a 6.00ax 7.00 8.00 8.00c
KBCategory: kbtool kbprb
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.