PRB: Compiler May Generate Near Calls to Far Helper Functions

ID Number: Q72703

6.00 6.00a 6.00ax | 6.00 6.00a

MS-DOS | OS/2

buglist6.00 buglist6.00a buglist6.00ax fixlist7.00

Summary:

SYMPTOMS

The following warning message is usually an indication of an

attempt to call a function that is placed in a far segment with the

alloc_text pragma in a small model program without first declaring

the function with the _far keyword:

C4185: near call to 'function' in different segment

However, under some circumstances the Microsoft C compiler versions

6.0, 6.0a, and 6.0ax may generate this error for an internal helper

function when one of the functions inside the module is defined in

a separate segment using the alloc_text pragma.

RESOLUTION

There are two possible ways to work around this problem:

- Remove the alloc_text pragma from the code.

-or-

- Restructure the code in such a way that the error is not

generated. This may require the use of temporary variables or a

slight change to the code path in order to produce the same

answers with a different order of instructions. In the example,

this can be done by calculating tm->d before tm->b.

STATUS

Microsoft has confirmed this to be a problem in C versions 6.0,

6.0a, and 6.0ax. This problem was corrected in C/C++ version 7.0.

More Information:

The sample code below illustrates one such case of this behavior. If

the code is compiled for small memory model (/AS) and the alternate

math library (/FPa) is specified, the compiler generates the following

error:

warning C4185: near call to '__aFssts' in different segment

Sample Code

-----------

/* Compile options needed: /AS /FPa /c

*/

void pascal func1 (void);

#pragma alloc_text(_STUFF,func1)

typedef struct {

float a,b,c,d;

} tmatrix;

void pascal func1()

{

long lsin,lcos;

long scalar,xscale;

tmatrix *tm;

tm->c = (float)lsin/65536 * (float)scalar/65536;

tm->b = tm->c * -(float)xscale/65536;

tm->d = (float)lcos/65536 * (float)scalar/65536;

tm->a = tm->d * (float)xscale/65536;

}

Additional reference words: 6.00 6.00a 6.00ax