struct comparison

Niels J|rgen Kruse njk at freja.diku.dk
Sun Jul 16 01:10:30 AEST 1989


henry at utzoo.uucp (Henry Spencer) writes:

>In article <2874 at solo3.cs.vu.nl> maart at cs.vu.nl (Maarten Litmaath) writes:
>>Why does the PROGRAMMER have to go through all that trouble?
>>I just want to say:
>>      puts(mork == mindy ? "equal" : "unequal");
>>Is the ANSI committee trying to tell us the compiler cannot transform the
>>equality test into the correct member-by-member comparison code?

>Yes.  Think about unions.  Or pointers (do you compare the pointers or
>what they point at?).  The compiler just doesn't have enough information.

Just like the compiler doesn't have enough information to
initialize a union, right? !

A simple rule like comparing first members of unions and the
pointers themselves would work nicely in a lot of cases and
match the way initialization works.

Or comparison of structs with inconvenient members could just
be outlawed, which wouldn't reduce the usefullness much.

Or perhaps better, inconvenient members could just be ignored,
leaving them for the programmer to handle separately.
-- 
         Niels J|rgen Kruse
Email    njk at diku.dk
Mail     Tustrupvej 7, 2 tv, 2720 Vanlose, Denmark



More information about the Comp.std.c mailing list