[C] 从远堆栈中申请空间 →→→→→进入此内容的聊天室

来自 , 2020-04-07, 写在 C, 查看 105 次.
URL http://www.code666.cn/view/02e656ad
  1. #include <stdio.h>
  2. #include <alloc.h>
  3. #include <string.h>
  4. #include <dos.h>
  5.  
  6. int main ( void )
  7. {
  8.         char far *fptr;
  9.         char *str = "Hello";
  10.  
  11.         /* allocate memory for the far pointer */
  12.         fptr = farcalloc ( 10, sizeof ( char ) );
  13.  
  14.         /* copy "Hello" into allocated memory */
  15.         /*
  16.            Note: movedata is used because you
  17.            might be in a small data model, in
  18.            which case a normal string copy routine
  19.            can not be used since it assumes the
  20.            pointer size is near.
  21.         */
  22.         movedata ( FP_SEG ( str ), FP_OFF ( str ),
  23.                    FP_SEG ( fptr ), FP_OFF ( fptr ),
  24.                    strlen ( str ) );
  25.  
  26.         /* display string (note the F modifier) */
  27.         printf ( "Far string is: %Fs\n", fptr );
  28.  
  29.         /* free the memory */
  30.         farfree ( fptr );
  31.  
  32.         return 0;
  33. }
  34.  

回复 "从远堆栈中申请空间"

这儿你可以回复上面这条便签

captcha