Microsoft KB Archive/37632

{|
 * width="100%"|

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

 * }

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 &quot;u&quot; and &quot;w&quot; 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 &quot;static&quot; 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

Issue type :

Technology : kbVCsearch kbAudDeveloper kbCVCComp