Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!cmcl2!rutgers!mit-eddie!uw-beaver!tikal!amc!pilchuck!dataio!bright From: bright@dataio.Data-IO.COM (Walter Bright) Newsgroups: comp.lang.c Subject: Re: swaps with arrays Message-ID: <1361@dataio.Data-IO.COM> Date: Thu, 10-Sep-87 14:25:44 EDT Article-I.D.: dataio.1361 Posted: Thu Sep 10 14:25:44 1987 Date-Received: Sat, 12-Sep-87 09:46:36 EDT References: <2376@zeus.TEK.COM> <110@umigw.MIAMI.EDU> Reply-To: bright@dataio.UUCP (Walter Bright) Organization: Data I/O Corporation; Redmond, WA Lines: 48 In article <110@umigw.MIAMI.EDU> steve@umigw.UUCP (steve emmerson) writes: >In article <1354@dataio.Data-IO.COM> bright@dataio.Data-IO.COM (Walter >Bright) wrote: >| Having a typeof would make creation of 'generic' routines possible: >| #define swap(a,b) { typeof(a) tmp; tmp = a; a = b; b = tmp; } > >To which I responded in article "<109@umigw.MIAMI.EDU> steve@umigw.UUCP" >saying: >+-------- >|[swap macro] also won't work with pure array objects (i.e. swapping one >|array with another). A generic routine should be able to work with >|*anything*. >+-------- > >Well, I can't speak for everyone ;-), but if I was given a generic swap >routine that only worked on a subset of all possible data types ... >well, I might consider it very useful, but I wouldn't consider it >generic. Someone please correct me if I'm wrong, but I believe a >"generic" routine is one that will work for any type of input (with a >caveat for the above example that the two arguments have the same >type). Now, in the original article, Walter Bright had the word >"generic" in quotes. Perhaps he was thinking along these lines and >ment to imply a "pseudo" or "quasi" generic routine (Walter?). I did mean generic. I know that the above won't work with arrays. But then, all battle-scarred C programmers know that how arrays work is botched in C, they just don't work like other types: int a[5],b[5]; a = b; /* copy contents of b to a */ if (a == b) /* if contents match */ ... func(a); /* push entire array on stack */ Of course, none of the above works as 'expected'. This also means that the usefulness of typedef's is compromised, you still have to be cognizant if your typedef is an array or a struct or a basic type. The symmetry and beauty of a language is inversely proportional to the number of if (special case) then kludge; constructs in the parser. A quick look at my compiler (Datalight) sources confirms that C is jammed with ifs! Don't get me wrong, C is my language of choice for most of my programs. But it does have its flaws...