Article View: comp.std.c
Article #351struct comparison - reprise
From: Maarten Litmaath
Date: Fri, 21 Jul 1989 01:52
Date: Fri, 21 Jul 1989 01:52
58 lines
2581 bytes
2581 bytes
It seems I'm not the only one in favor of (a limited form of) struct
comparison. On my `traditional struct complex' example
struct complex {
int Re;
int Im;
} z, w;
...
if (z == w) ...
Henry Spencer wrote something like
"Then how about struct addition, sonny?"
to which I say
"Yes! Another useful struct operation!"
Of course the structure elements must be addable, i.e. no pointers etc..
(There we go again, Blair!)
Arrays would be added member-wise. Hmm, sounds interesting...
Another point raised by Henry
"How about polar representation of complex numbers and
non-uniqueness?"
was nicely dealt with by Roelof Vuurboom. Mathematical problems caused by
(inadequate) representation of mathematical quantities, and language
definitions are two different things. Here's another example:
prod = z * w;
would be equivalent to
prod.Re = z.Re * w.Re;
prod.Im = z.Im * w.Im;
which is NOT the representation of the product of the complex numbers
represented by `z' and `w'. So what? YOUR fault, not the language's.
To Henry's remark
"You want C++, not C."
I say
"For the `struct complex' example? Maybe. But does this mean
any innovation should be swept off the table?"
As Bernard A. Badger Jr. says, "you throw out the useful comparisons with
the ill-defined ones. It is perfectly well-defined and quite handy
to define a simple member-by-member comparison on structs and arrays.
The only thing you give up are the unions. Comparison of pointers is
defined to be comparison of the pointers themselves, just as always."
Roelof Vuurboom again:
"I've still got an awful lot of structs *which occur in the real world*
for which I can (and several times wished I could) do a sensible comparison."
--
"Mom! Eric Newton broke the day! In 24 |Maarten Litmaath @ VU Amsterdam:
parts!" (Mike Schmitt in misc.misc) |maart@cs.vu.nl, mcvax!botter!maart
Technical Details
Message-ID:
<2918@kappl.cs.vu.nl>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!cs.utexas.edu!uunet!mcvax!hp4nl!botter!star.cs.vu.nl!maartReferences:
<2874@solo3.cs.vu.nl> <1989Jul14.155312.2063@utzoo.uucp> <2878@kappl.cs.vu.nl> <1989Jul15.210821.7950@utzoo.uucp> <167@ssp1.idca.tds.philips.nl> <1989Jul18.020424.2392@utzoo.uucp> <2335@trantor.harris-atd.com> <2261@auspex.auspex.com> <171@ssp1.idca.tds.pShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!cs.utexas.edu!uunet!mcvax!hp4nl!botter!star.cs.vu.nl!maart From: maart@cs.vu.nl (Maarten Litmaath) Newsgroups: comp.std.c Subject: struct comparison - reprise Message-ID: <2918@kappl.cs.vu.nl> Date: 21 Jul 89 01:52:06 GMT References: <2874@solo3.cs.vu.nl> <1989Jul14.155312.2063@utzoo.uucp> <2878@kappl.cs.vu.nl> <1989Jul15.210821.7950@utzoo.uucp> <167@ssp1.idca.tds.philips.nl> <1989Jul18.020424.2392@utzoo.uucp> <2335@trantor.harris-atd.com> <2261@auspex.auspex.com> <171@ssp1.idca.tds.p Organization: V.U. Informatica, Amsterdam, the Netherlands Lines: 58