home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.pascal
- Path: sparky!uunet!mcsun!sun4nl!star.cs.vu.nl!sbakker
- From: sbakker@cs.vu.nl (Bakker S)
- Subject: Re: Comparing record types
- Message-ID: <Bxt7yK.L2H@cs.vu.nl>
- Sender: news@cs.vu.nl
- Organization: Fac. Wiskunde & Informatica, VU, Amsterdam
- References: <92316.095144F0O@psuvm.psu.edu> <1992Nov13.001219.588@trl.oz.au>
- Date: Mon, 16 Nov 1992 12:56:43 GMT
- Lines: 52
-
- jbm@hal.trl.OZ.AU (Jacques Guy) writes:
-
- >That is indeed pretty poor, as it is quite illogical
- >to be able to assign a record to another, but not
- >compare them for equality!
-
- >I tried a couple of tricks, which failed, and had to
- >turn back to the age-old trick, which alas limits you
- >to records up to 256 bytes long:
-
- >type aRecord=record x,y,z: integer end;
- > pseudoRecord=string[SizeOf(aRecord)-1];
- ^^^^^^
- >var x,y: aRecord;
- >begin x:=y;
- > if pseudoRecord(x)=pseudoRecord(y) then (*....*)
-
- >end.
-
- >No, I don't like it either and I'd like to hear of any
- >better way too. Anyone, please?
-
- Well, this won't work. Consider the case in which the first byte of both
- records is null. The Pascal runtime compare routine will simply return equal
- regardless of the rest of the record.
-
-
- type aRecord=record x,y,z: integer end;
- pseudoRecord=packed array [1..SizeOf(aRecord)] of char;
- ^^^^^^^^^^^^
- var x,y: aRecord;
- begin x:=y;
- if pseudoRecord(x)=pseudoRecord(y) then (*....*)
- end.
-
- Now this *will* work, since the runtime code will compare *all* bytes (well,
- at least until there's a difference). You might also make pseudoRecord a
- function returning a string, with the length byte set properly (of course,
- this results in terrible performance).
-
-
- Huibert & Steven.
-
- [=============================================================================]
- | Steven Bakker, Vrije Universiteit Amsterdam. |
- | sbakker@cs.vu.nl |
- [-----------------------------------------------------------------------------]
- | ".. if a tree falls in the woods, and there's no one there to hear it, does |
- | it fall upwards or downwards. And its corollary, if a deaf man falls in the |
- | woods, does he make a sound?" |
- | -- Captain Rick. |
- [=============================================================================]
-