struct comparison

Guy Harris guy at auspex.auspex.com
Sat Jul 22 04:38:46 AEST 1989


>1. unions, bit fields (and the related case of data padding)
>
>Agreed. But my argument above is that if I exclude these cases I've
>still got a very relevant operation.

I've seen no indication that it's sufficiently relevant *that it should
be added to the language*; any definition of structure comparison would
be peppered with caveats like "no unions" and "no arrays" and "it
compares pointer values, not what they point to" and the like.

Yes, there have been cases I've seen where it might have been
convenient, but I really *can* live with doing the member-by-member
comparison myself.  And, given that there's no prior art, I agree with
X3J11's decision to leave it out.  If somebody sticks it into their
compiler as an extension and we can really find out from experience
whether enough people actually *would* use it enough to justify its
existence, then it can be considered as an extension if it actually is
used enough and doesn't confuse people.

>3. polar complex example
>
>It took a while before I began to get the sneaky feeling that maybe 
>Henry Spencer had put one over me here.
>
>His argument was that because a certain _mathematical_ concept (complex
>comparison) couldn't be supported this was (one of the) grounds for 
>omitting a _language_ concept (struct comparison). 

I think Henry's point, like mine, is that the total number of cases
where somebody, in effect, defines an equality operator over some data
type seems likely to be much larger than the number of cases where this
operator is just a member-by-member comparison; complex numbers
represented in polar form are one example.  Given that, I'd like to see
some real-world experience with such a feature before seeing it blessed
in a standard.... 

The original poster *did*, in fact, effectively ask "why isn't structure
comparison in ANSI C"?  The question was answered, by Henry and others,
and I have yet to see a *single* response to that answer that, to me,
would justify the inclusion of such a feature *in the ANSI C standard*,
given the lack of prior art (and yes, there *was* prior art for function
prototypes, namely in C++; it may not have been in an otherwise "pure" C
implementation, but at least it existed).  I suspect *I* wouldn't use
structure comparison if it were available to me in C; I'm almost certain
I wouldn't use it if it were available to me in C++ - I'd define an "="
operator for the data type, instead, and not be forced to rely on
member-by-member comparison being the right answer.



More information about the Comp.std.c mailing list