Automatic Casting from Near Pointer to Far PointerLast reviewed: July 17, 1997Article ID: Q43486 |
6.00 6.00a 6.00ax 7.00 | 6.00 6.00a | 1.00 1.50
MS-DOS | OS/2 | WINDOWSkbtool The information in this article applies to:
SUMMARYIn 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 INFORMATIONTwo 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 ** casting is performed with assignment. ** Segment is DS. */ npChar = malloc( 100 ); printf("In main()\n"); printf("npChar = %p\n", npChar); printf("lpChar = %Fp\n\n", lpChar); 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 = %Fp\n", p);}
|
Additional reference words: kbinf 1.00 1.50 6.00 6.00a 6.00ax 7.00 8.00
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |