Path: utzoo!utgpu!watmath!att!pacbell!ames!zodiac!joyce!unix!husc6!ginosko!xanth!mcnc!spl From: spl@mcnc.org (Steve Lamont) Newsgroups: comp.lang.c Subject: Re: What I'd really like to see in an if-statement... Message-ID: <5040@alvin.mcnc.org> Date: 8 Aug 89 11:55:46 GMT References: <5024@alvin.mcnc.org> <1300@atanasoff.cs.iastate.edu> <456@helios.prosys.se> <14521@bfmny0.UUCP> <1864@salgado.Solbourne.COM> <14522@bfmny0.UUCP> Reply-To: spl@mcnc.org.UUCP (Steve Lamont) Organization: Microelectronics Center of NC; RTP, NC Lines: 56 In article <14522@bfmny0.UUCP> tneff@bfmny0.UUCP (Tom Neff) writes: >I suppose I might as well point out that if speed is not crucial, >you could always code a C function to do the triadic compare: > > if (triadc(min, '<', thisval, '<=', max)) ... > Though the following isn't exactly what I intended (generating even more keystrokes than the simpler and, to the mathematical among us, more straightforward ( a < b < c ) you don't need to code triadc() as a function. You could indeed code it as a macro, to wit #define triadc(a,b,c,d,e) ( ( a b c ) && ( c d e ) ) ... if ( triadc( 0.0, <, x, <, 1.0 ) ) ... which will expand to if ( ( ( 0.0 < x ) && ( x < 1.0 ) ) ) ... or at least it does on my IRIS. Haven't tested it on other versions of CPP, so I can't say whether it is a general solution or one unique to the preprocessor on the IRIS 4D series of machines. Note that while this effectively does more or less what I want, it is a kludge at best and I don't know how one would go about implementing ( a < b < c ) in C without either overloading the inequality operators, breaking currently working programs [does anyone really code something like the above to mean ( a < b ) < c in a useful, working C program??? I'd be curious to see an example where such a construction would be meaningful.] Perhaps in ANSI C II (K&R Strike Back?? :-) ) we could add operators .<., .>., .<=., and .>=. (big :-) here ). Wouldn't you just love to code ( a .<. b .<. c ) ????? -- spl Steve Lamont, sciViGuy EMail: spl@ncsc.org North Carolina Supercomputing Center Phone: (919) 248-1120 Box 12732/RTP, NC 27709