home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / pascal / 5306 < prev    next >
Encoding:
Internet Message Format  |  1992-09-10  |  1.6 KB

  1. Path: sparky!uunet!noc.near.net!ds5000!cschmidt
  2. From: cschmidt@ds5000.DAC.Northeastern.edu (Christopher Schmidt)
  3. Newsgroups: comp.lang.pascal
  4. Subject: Re: LENGTH and POS in TP 5.5
  5. Message-ID: <7379@ds5000.DAC.Northeastern.edu>
  6. Date: 10 Sep 92 22:24:47 GMT
  7. Reply-To: cschmidt@ds5000 (Christopher Schmidt)
  8. Organization: Leelanau Computing Inc
  9. Lines: 30
  10.  
  11. > > The TP 5.5 documentation says the LENGTH function returns a value
  12. > > of type integer.  Apparently, it actually returns a value of type
  13. > > byte.  
  14. > Clearly the easiest fix would be to change the manuals so that Length
  15. > and Pos are properly documented; what would be the problem in that?
  16.  
  17. Ok fine.
  18.  
  19. Got several mail messages from folks wondering why this matter caused
  20. a problem the first place.  I had written a general purpose function
  21. that allocates storage for a string, using the following expression to
  22. calculate the amount of storage required, where "s" is the formal
  23. parameter containing the string for which space is to be allocated:
  24.  
  25.         succ (length (s))
  26.  
  27. This expression works fine unless the length of "s" is 255, in which
  28. case this expression returns zero.
  29.  
  30. One of my programs uses my string-allocation function to store lines
  31. from an input text file.  The program ran correctly until one day I
  32. (accidentally) used my program to read a binary file, which meant the
  33. input buffer sometimes contained strings of length 255, which had
  34. never happened when reading standard text files.  The program blew up
  35. when it later tried to deallocate a block of memory of length zero.
  36.  
  37. Christopher Schmidt
  38. Waltham, Massachusetts, USA
  39. cschmidt@lynx.northeastern.edu
  40.