[C] 从远堆中释放一块 →→→→→进入此内容的聊天室

来自 , 2020-09-22, 写在 C, 查看 141 次.
URL http://www.code666.cn/view/b5c01503
  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 might be in a small data model,
  17.            in which case a normal string copy routine can't be used since it
  18.            assumes the pointer size is near.
  19.         */
  20.         movedata ( FP_SEG ( str ), FP_OFF ( str ),
  21.                    FP_SEG ( fptr ), FP_OFF ( fptr ),
  22.                    strlen ( str ) );
  23.  
  24.         /* display string (note the F modifier) */
  25.         printf ( "Far string is: %Fs\n", fptr );
  26.  
  27.         /* free the memory */
  28.         farfree ( fptr );
  29.  
  30.         return 0;
  31. }
  32.  

回复 "从远堆中释放一块"

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

captcha