home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / pascal / 6624 < prev    next >
Encoding:
Text File  |  1992-11-16  |  2.2 KB  |  64 lines

  1. Newsgroups: comp.lang.pascal
  2. Path: sparky!uunet!mcsun!sun4nl!star.cs.vu.nl!sbakker
  3. From: sbakker@cs.vu.nl (Bakker S)
  4. Subject: Re: Comparing record types
  5. Message-ID: <Bxt7yK.L2H@cs.vu.nl>
  6. Sender: news@cs.vu.nl
  7. Organization: Fac. Wiskunde & Informatica, VU, Amsterdam
  8. References: <92316.095144F0O@psuvm.psu.edu> <1992Nov13.001219.588@trl.oz.au>
  9. Date: Mon, 16 Nov 1992 12:56:43 GMT
  10. Lines: 52
  11.  
  12. jbm@hal.trl.OZ.AU (Jacques Guy) writes:
  13.  
  14. >That is indeed pretty poor, as it is quite illogical
  15. >to be able to assign a record to another, but not
  16. >compare them for equality!
  17.  
  18. >I tried a couple of tricks, which failed, and had to 
  19. >turn back to the age-old trick, which alas limits you
  20. >to records up to 256 bytes long:
  21.  
  22. >type aRecord=record x,y,z: integer end;
  23. >     pseudoRecord=string[SizeOf(aRecord)-1];
  24.                    ^^^^^^
  25. >var  x,y: aRecord;
  26. >begin x:=y;
  27. >      if pseudoRecord(x)=pseudoRecord(y) then (*....*)
  28.  
  29. >end.
  30.  
  31. >No, I don't like it either and I'd like to hear of any
  32. >better way too. Anyone, please?
  33.  
  34. Well, this won't work. Consider the case in which the first byte of both
  35. records is null. The Pascal runtime compare routine will simply return equal
  36. regardless of the rest of the record.
  37.  
  38.  
  39. type aRecord=record x,y,z: integer end;
  40.      pseudoRecord=packed array [1..SizeOf(aRecord)] of char;
  41.           ^^^^^^^^^^^^
  42. var  x,y: aRecord;
  43. begin x:=y;
  44.       if pseudoRecord(x)=pseudoRecord(y) then (*....*)
  45. end.
  46.  
  47. Now this *will* work, since the runtime code will compare *all* bytes (well,
  48. at least until there's a difference). You might also make pseudoRecord a
  49. function returning a string, with the length byte set properly (of course,
  50. this results in terrible performance).
  51.  
  52.  
  53.                         Huibert & Steven.
  54.  
  55. [=============================================================================]
  56. | Steven Bakker, Vrije Universiteit Amsterdam.                      |
  57. | sbakker@cs.vu.nl                                             |
  58. [-----------------------------------------------------------------------------]
  59. | ".. if a tree falls in the woods, and there's no one there to hear it, does |
  60. | it fall upwards or downwards. And its corollary, if a deaf man falls in the |
  61. | woods, does he make a sound?"                              |
  62. |                    -- Captain Rick.              |
  63. [=============================================================================]
  64.