home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!UB.com!pippen.ub.com!rfries
- From: rfries@sceng.ub.com (Robert Fries)
- Subject: Re: Problem with Turbo-C: calculating with pointers
- Message-ID: <rfries.156@sceng.ub.com>
- Sender: news@pippen.ub.com (The Daily News)
- Nntp-Posting-Host: 128.203.1.151
- Organization: Ungermann Bass
- References: <1993Jan7.112219.578@reks.uia.ac.be>
- Date: Thu, 7 Jan 1993 16:06:48 GMT
- Lines: 45
-
- In article <1993Jan7.112219.578@reks.uia.ac.be> 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:
-
- >#include <alloc.h>
-
- >main()
- >{
- >char *pointer,*begin,*end;
- >long size;
-
- >size=71800;
- >pointer=(char *)farmalloc(size*sizeof(char));
- >begin=pointer;
- >end=pointer+size;
- >printf("%p %p %ld",begin, end, end - begin);
- >}
-
- >I would expect end - begin to return 71800. However it seems to return 6264.
- >This is exactly 64K less.
- >If this happens for all pointer calculations, I'm in big trouble.
- >Any ideas to solve this.
-
- >All help is greatly appreciated.
-
- >Peter
-
- You need to declare the pointers as huge pointers:
-
- char huge *pointer, huge *begin, huge *end;
-
- Robert
-
- //////////////////////////////////////////////////////////////////////////
- Robert Fries
- Ungermann-Bass Inc.
-
- DISCLAIMER:
- Opinions contained herein are my own, and are not necessarily those
- of Ungermann-Bass.
- //////////////////////////////////////////////////////////////////////////
-