What I'd really like to see in an if-statement...
Steve Lamont
spl at mcnc.org
Tue Aug 8 21:55:46 AEST 1989
In article <14522 at bfmny0.UUCP> tneff at 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 at ncsc.org
North Carolina Supercomputing Center Phone: (919) 248-1120
Box 12732/RTP, NC 27709
More information about the Comp.lang.c
mailing list