Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site unc.UUCP Path: utzoo!watmath!clyde!burl!ulysses!gamma!exodus!mhtsa!mh3bs!eagle!harpo!decvax!mcnc!unc!tim From: tim@unc.UUCP Newsgroups: net.lang.c Subject: Re: What Can't C Do? (struct & string compares) Message-ID: <6922@unc.UUCP> Date: Thu, 15-Mar-84 12:24:18 EST Article-I.D.: unc.6922 Posted: Thu Mar 15 12:24:18 1984 Date-Received: Sat, 17-Mar-84 03:54:43 EST References: <178@harvard.UUCP> Organization: CS Dept., U. of N. Carolina at Chapel Hill Lines: 36 There are some tricky issues involved in structure comparison, and there is no single best way to do it for all applications. The difficulty comes in when you have pointers as attributes (sorry, "members") of structures. You can do a standard quasi-numerical comparison on them, but that means that two pointers to different but equivalent objects will be considered unequal, which is not always what you want. On the other hand, if you descend into pointers, you will probably need to do it by user-invisible functions, which any true C hacker would gag at, and you run the risk of hitting a cycle in the structure and recursing until the stack overflows. The first method seems to be the only one tolerable; my question is, how usefiul would it be? Obviously, it would be good for complex numbers and a few other applications. What does everyone else think? Now about string comparison. After I suggested this, someone accused me of being insensitive to the perils of creeping featurism. I assure you that I am well aware of that problem; otherwise, I would have had a lot more suggestions. However, I don't think that extending comparison operators to apply to an existing data type, for which there is already a common ordering function known and often used, is really "adding" something -- it is just making the comparison operators more orthogonal. I would also support doing this in a more general way by allowing array comparisons when the array is of a comparable data type; the compiler can frequently generate more efficient code for this than the user easily can anyway. The big problem with all this is that there is really no such thing as arrays in C. There are pointers, but comparison is already defined for them. A smaller problem is that there are two types of (non)arrays which we'd want to compare: fixed-length and null-terminated. Can anyone come up with a clean solution for these problems? I would rather have just the string comparison than no extension of comparison at all, in any case. -- Tim Maroney, The Censored Hacker mcnc!unc!tim (USENET), tim.unc@csnet-relay (ARPA) All opinions expressed herein are completely my own, so don't go assuming that anyone else at UNC feels the same way.