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

  1. Newsgroups: comp.lang.c
  2. From: raph@panache.demon.co.uk (Raphael mankin)
  3. Path: sparky!uunet!pipex!demon!panache.demon.co.uk!raph
  4. Subject: Re: Problem with Turbo-C: calculating with pointers 
  5. Distribution: world
  6. References: <1993Jan7.112219.578@reks.uia.ac.be>
  7. Organization: Solvfield Ltd.
  8. Reply-To: raph@panache.demon.co.uk
  9. X-Mailer: Simple NEWS 1.90 (ka9q DIS 1.19)
  10. Lines: 37
  11. Date: Fri, 8 Jan 1993 20:26:30 +0000
  12. Message-ID: <726524790snz@panache.demon.co.uk>
  13. Sender: usenet@demon.co.uk
  14.  
  15. In article <1993Jan7.112219.578@reks.uia.ac.be> derijkp@reks.uia.ac.be writes:
  16.  
  17. >I am porting a program (working on different platforms such as VAX and DEC) to
  18. >the PC. I am using Turbo C++ v.3.0. I compile using the huge memory model.
  19. >I seem to have tracked down the problem (well, one of the problems.) I don't
  20. >know what to do about it though. Here's a little program to illustrate the
  21. >problem:
  22. >
  23. >#include <alloc.h>
  24. >
  25. >main()
  26. >{
  27. >char *pointer,*begin,*end;
  28. >long size;
  29. >
  30. >size=71800;
  31.       ^^^^^
  32. make this 71800L and it will work. This compiler like many others treats integer
  33. cosntants as 16-bit ints. 61800-65536 == 6264.
  34. QED.
  35.  
  36. >pointer=(char *)farmalloc(size*sizeof(char));
  37. >begin=pointer;
  38. >end=pointer+size;
  39. >printf("%p %p %ld",begin, end, end - begin);
  40. >}
  41. >
  42. >I would expect end - begin to return 71800. However it seems to return 6264.
  43. >This is exactly 64K less.
  44. >If this happens for all pointer calculations, I'm in big trouble.
  45. >Any ideas to solve this.
  46.  
  47. Better still, don't do pointer arithmetic. It is a sure route to trouble.
  48.  
  49. -- 
  50. --------------
  51. Raphael Mankin            Nil taurus excretum
  52.