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

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!darwin.sura.net!convex!constellation!prowler.ecn.uoknor.edu!norlin
  3. From: norlin@prowler.ecn.uoknor.edu (Norman Lin)
  4. Subject: Re: Problem with Turbo-C: calculating with pointers
  5. Sender: usenet@constellation.ecn.uoknor.edu (Usenet Administrator)
  6. Message-ID: <C0HrCx.12F@constellation.ecn.uoknor.edu>
  7. Date: Thu, 7 Jan 1993 16:05:18 GMT
  8. References: <1993Jan7.112219.578@reks.uia.ac.be>
  9. Nntp-Posting-Host: prowler.ecn.uoknor.edu
  10. Organization: Engineering Computer Network, University of Oklahoma, Norman, OK, USA
  11. Lines: 24
  12.  
  13. 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. >I would expect end - begin to return 71800. However it seems to return 6264.
  22. >This is exactly 64K less.
  23.  
  24. In the "huge" memory model in Turbo C++, all pointers default to "far"
  25. pointers.  Far pointers, it says in the TC++ manual, should not be used
  26. for pointer arithmetic because they are not segment aligned.  Declare the
  27. pointers to be huge pointers (e.g. char huge *begin, huge *end), and the
  28. math should work, because huge pointers are segment aligned.
  29.  
  30. In general, if you're doing ANY pointer arithmetic, you should not use far
  31. pointers, and remember, the huge memory model defaults to using far pointers.
  32. You should be aware that using huge pointers incurs slight performance
  33. overhead (due to the necessity of normalization).
  34.  
  35. Norman Lin
  36. norlin@mailhost.ecn.uoknor.edu
  37.