struct comparison - reprise

Maarten Litmaath maart at cs.vu.nl
Fri Jul 21 11:52:06 AEST 1989


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 at cs.vu.nl, mcvax!botter!maart



More information about the Comp.std.c mailing list