home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / c / 19365 < prev    next >
Encoding:
Text File  |  1993-01-07  |  1.6 KB  |  58 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!UB.com!pippen.ub.com!rfries
  3. From: rfries@sceng.ub.com (Robert Fries)
  4. Subject: Re: Problem with Turbo-C: calculating with pointers
  5. Message-ID: <rfries.156@sceng.ub.com>
  6. Sender: news@pippen.ub.com (The Daily News)
  7. Nntp-Posting-Host: 128.203.1.151
  8. Organization: Ungermann Bass
  9. References: <1993Jan7.112219.578@reks.uia.ac.be>
  10. Date: Thu, 7 Jan 1993 16:06:48 GMT
  11. Lines: 45
  12.  
  13. In article <1993Jan7.112219.578@reks.uia.ac.be> derijkp@reks.uia.ac.be (Peter De Rijk) writes:
  14.  
  15. >I am porting a program (working on different platforms such as VAX and DEC) to
  16. >the PC. I am using Turbo C++ v.3.0. I compile using the huge memory model.
  17. >I seem to have tracked down the problem (well, one of the problems.) I don't
  18. >know what to do about it though. Here's a little program to illustrate the
  19. >problem:
  20.  
  21. >#include <alloc.h>
  22.  
  23. >main()
  24. >{
  25. >char *pointer,*begin,*end;
  26. >long size;
  27.  
  28. >size=71800;
  29. >pointer=(char *)farmalloc(size*sizeof(char));
  30. >begin=pointer;
  31. >end=pointer+size;
  32. >printf("%p %p %ld",begin, end, end - begin);
  33. >}
  34.  
  35. >I would expect end - begin to return 71800. However it seems to return 6264.
  36. >This is exactly 64K less.
  37. >If this happens for all pointer calculations, I'm in big trouble.
  38. >Any ideas to solve this.
  39.  
  40. >All help is greatly appreciated.
  41.  
  42. >Peter
  43.  
  44. You need to declare the pointers as huge pointers:
  45.  
  46. char huge *pointer, huge *begin, huge *end;
  47.  
  48. Robert
  49.  
  50. //////////////////////////////////////////////////////////////////////////
  51. Robert Fries
  52. Ungermann-Bass Inc.
  53.  
  54. DISCLAIMER:
  55.     Opinions contained herein are my own, and are not necessarily those
  56.     of Ungermann-Bass.
  57. //////////////////////////////////////////////////////////////////////////
  58.