N-ary < operator (was What I'd really like to see in an if-statement...)

Craig Finseth fin at uf.msc.umn.edu
Tue Aug 8 00:51:25 AEST 1989


As previous posters have mentioned, the C language already accepts the
syntax:

	a < b < c

as valid, with (possibly) surprizing semantics.  It is diffcult to
imagine (i.e., I cannot) an upwardly-compatible extension to C that
"corrects" the semantics.

However, do not despair.  You can achieve a similar goal merely be
writing a function such as:

	int
	between(const int a, const int b, const int c)
		{
		return((a < b) && (b < c));
		}

which returns 1 if b is between a and c.  While not as elegant as a
built-in solution, it has the advantages of working on just about all
C compilers (you can write it with the old-style parameter
declarations) and use it now.

(For the record, I added "between" (a < b < c), "outside" (c > b > a),
and "within" (a <= b <= c) operators to a little-used data collection
language that I developed.)

Craig A. Finseth			fin at msc.umn.edu [CAF13]
Minnesota Supercomputer Center, Inc.	(612) 624-3375



More information about the Comp.lang.c mailing list