Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!rutgers!mit-eddie!uw-beaver!ssc-vax!cxsea!blm From: blm@cxsea.UUCP (Brian Matthews) Newsgroups: comp.lang.c Subject: Re: Writing readable code Message-ID: <2148@cxsea.UUCP> Date: Mon, 3-Aug-87 11:28:36 EDT Article-I.D.: cxsea.2148 Posted: Mon Aug 3 11:28:36 1987 Date-Received: Thu, 6-Aug-87 04:33:58 EDT References: <1158@copper.TEK.COM> <6858@auspyr.UUCP> <17171@cca.CCA.COM> <22250@sun.uucp> <525@murphy.UUCP> Reply-To: blm@cxsea.UUCP (Brian Matthews) Organization: Computer X Inc. Lines: 30 In article <525@murphy.UUCP> dave@murphy.UUCP (Dave Cornutt) writes: |In article <22250@sun.uucp>, guy%gorodish@Sun.COM (Guy Harris) writes: |> Also, you didn't address the issue of |> if (!strcmp(str1, str2)) |This has always been one of my pet peeves. Even after years of C |programming experience, I still find myself sometimes looking at this |and reading it as "if str1 is not equal to str2..." I wrote a little |function of my own which takes a string containing an operator in |between the other two arguments, so it looks something like this: | |if (strcompare(str1,"==",str2)) I usually don't like mucking up code with lots of strange macros, but one I do find useful is something like: #define strrel(s,op,t) (strcmp((s), (t)) op 0) where op can be any of relational operators, ==, <, etc. So, your example would become: if (strrel(str1,==,str2)) This avoids the overhead of an additional procedure call, and parsing "==" (or "<", or whatever), but maintains the (in my opinion) increased readability. -- Brian L. Matthews "A man with one watch knows ...{mnetor,uw-beaver!ssc-vax}!cxsea!blm what time it is; a man with +1 206 251 6811 two watches isn't so sure." Computer X Inc. - a division of Motorola New Enterprises