INF: Automatic Casting from Near Pointer to Far Pointer

ID Number: Q43486

5.10 6.00 6.00a 6.00ax | 5.10 6.00 6.00a

MS-DOS | OS/2

Summary:

In Microsoft C, near pointers are automatically cast to far pointers

when a near to far conversion is required. In cases where near

pointers are promoted to far pointers, the segment is the same as

DGROUP. In cases where functions are prototyped to accept a far

pointer, no explicit conversion is required.

More Information:

Two of the cases of the automatic casting are shown in the sample code

below:

Sample Code

-----------

/* Compile options needed: /AS or /AM in order to get

malloc() mapped to _nmalloc()

*/

#include <stdio.h>

#include <malloc.h>

void FuncName (char far *) ;

void main (void)

{

char far * lpChar ;

char * npChar ;

lpChar = malloc( 100 ); /* malloc is mapped to _nmalloc,

** and returns near pointer, automatic type

** casting is performed with assignment */

FuncName( npChar ) ; /* npChar is converted to a far pointer

** with the segment address to be DS */

}

void FuncName (char far * p)

{

printf("In function FuncName()\n");

printf("p = %p\n", p);

}

Additional reference words: 6.0 6.00 6.0a 6.00a 6.0ax 6.00ax

quickc 2.0 2.00 2.01 2.5 2.50 2.51