home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!darwin.sura.net!convex!constellation!prowler.ecn.uoknor.edu!norlin
- From: norlin@prowler.ecn.uoknor.edu (Norman Lin)
- Subject: Re: Problem with Turbo-C: calculating with pointers
- Sender: usenet@constellation.ecn.uoknor.edu (Usenet Administrator)
- Message-ID: <C0HrCx.12F@constellation.ecn.uoknor.edu>
- Date: Thu, 7 Jan 1993 16:05:18 GMT
- References: <1993Jan7.112219.578@reks.uia.ac.be>
- Nntp-Posting-Host: prowler.ecn.uoknor.edu
- Organization: Engineering Computer Network, University of Oklahoma, Norman, OK, USA
- Lines: 24
-
- derijkp@reks.uia.ac.be (Peter De Rijk) writes:
-
- >I am porting a program (working on different platforms such as VAX and DEC) to
- >the PC. I am using Turbo C++ v.3.0. I compile using the huge memory model.
- >I seem to have tracked down the problem (well, one of the problems.) I don't
- >know what to do about it though. Here's a little program to illustrate the
- >problem:
-
- >I would expect end - begin to return 71800. However it seems to return 6264.
- >This is exactly 64K less.
-
- In the "huge" memory model in Turbo C++, all pointers default to "far"
- pointers. Far pointers, it says in the TC++ manual, should not be used
- for pointer arithmetic because they are not segment aligned. Declare the
- pointers to be huge pointers (e.g. char huge *begin, huge *end), and the
- math should work, because huge pointers are segment aligned.
-
- In general, if you're doing ANY pointer arithmetic, you should not use far
- pointers, and remember, the huge memory model defaults to using far pointers.
- You should be aware that using huge pointers incurs slight performance
- overhead (due to the necessity of normalization).
-
- Norman Lin
- norlin@mailhost.ecn.uoknor.edu
-