structure and array and string comparisons
rcd at opus.UUCP
rcd at opus.UUCP
Sun Apr 1 15:57:09 AEST 1984
<>
> Except for
> the problem with unions, the compiler has as much information about the
> structure as the programmer does--often more.
Actually, this isn't true either. If you think about situations in which
you want to compare structures, it is probably true a fair amount of the
time that the comparisons should be done in a particular order. That is,
you will want the effect of
if ((a.f1==b.f1) && (a.f2==b.f2) && ...)
where the compiler would not necessarily choose to compare f1 before f2.
The point is that the programmer may well have more information - he may be
able to decide which fields mismatch more often and arrange to compare them
first.
[An aside: I would conjecture that the efficiency gains from having the
compiler use special comparison instructions would probably be less overall
than the efficiency gains from having the programmer specify the
comparisons in optimal order.]
--
{hao,ucbvax,allegra}!nbires!rcd
More information about the Comp.lang.c
mailing list