What should be added to C
Gregory Smith
greg at utcsri.UUCP
Sun May 25 11:44:00 AEST 1986
In article <1497 at mmintl.UUCP> franka at mmintl.UUCP (Frank Adams) writes:
>
>>> o An andif clause for if statements.
>
>You would write:
>
> if (A) {
> X
> } andif (B) {
> Y
> } else {
> Z
> }
>
>This is equivalent to:
>
> if (!(A)) goto _Z;
> X
> if (B) {
> Y
> } else {
>_Z:
> Z
> }
>
Interesting - like a switch, but with dynamic conditions. How about
actually writing it like a switch:
switch(){ /* or just 'switch{' */
when A: X;
break;
when B: Y;
break;
default:
Z;
}
A and B, are arbitrary expressions which are evaluated in sequence.
Sorry about stealing the extra keyword. Actually, 'case' would work just
as well; and it wouldn't really be confusing, since one type of switch
*must* have a constant exp and the other type would have to have
non-constant expressions in reasonable usage. This would be easy to
compile, and much more readable than an if..else.. etc.
>>> o Any sort of multi-level break statement. There is no syntacticly clean
>>> way of adding this to C.
I don't agree. what about
statement ::= break ;
| break constant_exp ;
e.g. break 2;
would break the current loop *and* the enclosing one.
Of course, you can obfuscate this with
#define BRKS 3;
...
break BRKS; /* ;-) */
--
"We demand rigidly defined areas of doubt and uncertainty!" - Vroomfondel
----------------------------------------------------------------------
Greg Smith University of Toronto UUCP: ..utzoo!utcsri!greg
More information about the Comp.lang.c
mailing list