home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- From: raph@panache.demon.co.uk (Raphael mankin)
- Path: sparky!uunet!pipex!demon!panache.demon.co.uk!raph
- Subject: Re: Problem with Turbo-C: calculating with pointers
- Distribution: world
- References: <1993Jan7.112219.578@reks.uia.ac.be>
- Organization: Solvfield Ltd.
- Reply-To: raph@panache.demon.co.uk
- X-Mailer: Simple NEWS 1.90 (ka9q DIS 1.19)
- Lines: 37
- Date: Fri, 8 Jan 1993 20:26:30 +0000
- Message-ID: <726524790snz@panache.demon.co.uk>
- Sender: usenet@demon.co.uk
-
- In article <1993Jan7.112219.578@reks.uia.ac.be> derijkp@reks.uia.ac.be 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;
- ^^^^^
- make this 71800L and it will work. This compiler like many others treats integer
- cosntants as 16-bit ints. 61800-65536 == 6264.
- QED.
-
- >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.
-
- Better still, don't do pointer arithmetic. It is a sure route to trouble.
-
- --
- --------------
- Raphael Mankin Nil taurus excretum
-