"arithmetic if":: Re: Feature for the next C version
John Hascall
hascall at atanasoff.cs.iastate.edu
Thu Aug 3 00:37:36 AEST 1989
In article <1429 at crdgw1.crd.ge.com> davidsen at crdos1.UUCP (bill davidsen) writes:
>someone pointed out, I'm not looking for arithmetic IF, but a way to do
>three separate things based on a value, usually the compare of two
>values in a sort or tree search.
> Some interesting ideas:
> ifcase
> (a < b) code; code;
> (a == b) more(code);
> (a > b) still(more);
> endcase;
This reminds my of an exec language I somtimes program in (no, you
haven't heard of it), where you use:
cases begin
case (expression1) statement1
case (expression2) statement2
:
:
end
And it evaluates each expression in order and executes the (possibly
compound) statement of the first one (if any) which is true.
[and you just use "case (true)" at the end for "default:"].
Of course, neither of these solve the original problem of how to
execute a 3-way branch with a single expression evaluation.
Imagine extending the concept:
if (expr) s1; [else s2;]
to:
negative (expr) s1; [zero s2;] [positive s3;]
I can hear the C-purists screaming in agony :-)
John Hascall
More information about the Comp.lang.c
mailing list