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

ID Number: Q37632

5.10 6.00 6.00a 6.00ax 7.00 | 5.10 6.00 6.00a

MS-DOS | OS/2

buglist5.10 buglist6.00 buglist6.00a buglist6.00ax buglist7.00

Summary:

SYMPTOMS

The following warning is given in Microsoft C versions 5.1, 6.0,

6.0a, and 6.0ax when the address of a local variable is passed to a

function expecting a pointer and compiler options include either

/ASu, /ASw, /AMu, or /AMw:

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

In C/C++ version 7.0 the following warning is generated:

C4762: near/far mismatch in argument; conversion supplied

CAUSE

The segment setup codes u and w indicate to the compiler that it

can not count on SS being equal to DS. However, in the small and

medium memory model, data pointers are assumed to be near. The

function is expecting a near pointer relative to SS. Because SS

may not be equal to DS, the compiler issues the warning.

RESOLUTION

To eliminate the warning, do one of the following:

1. Declare the local variable with the static attribute

-or-

2. Prototype the receiving function as receiving a variable of

type _far.

-or-

3. Switch to compact or large memory model.

More Information:

The following sample code illustrates the situation.

Sample Code

-----------

/* Compile options needed: /AMw

*/

void inc( int * );

void main( )

{

int p = 666;

inc( &p ); /* address of stack variable */

}

void inc( int *p )

{

*p+=1;

}

Additional reference words: 5.10 6.00 6.00a 6.00ax 7.00