Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site druxy.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxl!ihnp4!drutx!druxy!jas From: jas@druxy.UUCP (ShanklandJA) Newsgroups: net.lang.c Subject: Re: structure and array and string comparisons Message-ID: <1056@druxy.UUCP> Date: Fri, 23-Mar-84 11:40:25 EST Article-I.D.: druxy.1056 Posted: Fri Mar 23 11:40:25 1984 Date-Received: Sun, 25-Mar-84 08:30:04 EST References: <253@opus.UUCP> <365@denelcor.UUCP> Organization: AT&T Information Systems Laboratories, Denver Lines: 32 For goodness' sake! When you need to do structure or array comparison, how hard is it to write a little macro that does the job? Under most circumstances, I can't see it taking more than 5 minutes. (Yes, people sometimes use structures with dozens -- or hundreds of fields. But how often? How often do such structures need to be compared in their entirety? Is it worth hacking up the language to accomodate such cases? The advantages of the macro approach are: (1) you get to interpret "equality" any way you want: dictionary order for some fields, numerical equality for others, etc.; pointers must point to one and the same object to be equal, or pointers to equal-valued objects are considered equal (and of course, you get to decide what makes the pointed-to objects "equal"); (2) you stop creeping featurism in its tracks. One objection I foresee is that people will say that the compiler could generate more efficient comparison code directly, say by emitting a single block-compare instruction to compare several truly adjacent fields ("truly adjacent" means no gap for alignment), whereas if you compare each field separately in a macro, the compiler will most likely emit separate compare instructions for each field. But I suggest the solution to that is to use a compiler that will optimize such code sequences into a single block-compare wherever possible. Granted, I'm not at all sure that a C compiler that optimizes to that extent exists anywhere, on any machine; but just wait.... Keep C small! Jim Shankland ..!ihnp4!druxy!jas