Boolean Operators Slighted in C

Daniel R. Levy levy at ttrdc.UUCP
Tue May 6 19:55:39 AEST 1986


In article <12329 at ucla-cs.ARPA>, jimc at ucla-cs.ARPA (Jim Carter) writes:
>I think it's useful!  As written, of course, it's semantically invalid,
>but what you really mean is "v <= e" (sic) or, to demonstrate where it's
>really useful,
>     array[horrendous] [subscript] [list] <= bigexpr;
>  rather than
>     if (array[h][s][l] < bigexpr) array[h][s][l] = bigexpr;
>Now "<=" already means something else so this syntax is not acceptable.
>How about "v < = e" with a mandatory blank?  This is atrocious human
>engineering but at least is parseable.  Anybody have any better ideas?
>--
>James F. Carter            (213) 206-1306
>UCLA-SEASnet; 2567 Boelter Hall; 405 Hilgard Ave.; Los Angeles, CA 90024
>UUCP:...!{ihnp4,ucbvax,{hao!cepu}}!ucla-cs!jimc  ARPA:jimc at locus.UCLA.EDU

First, one could use the preprocessor to help:
#define UPMAX(i,j)	if ((i) < (j)) (i) = (j)
...
UPMAX(array[h][s][l],bigexpr);

While the output of cpp would look real messy, comp would handle this just
fine.  Of course, you lose (as with any macro which uses an argument more
than once) if the arguments have side effects such as ++ (but that isn't
the case here, right?).  Or if you know that the optimizer is not smart
enough to catch this and will evaluate the entire array[h][s][l] including
subscripts twice (as well as bigexpr), you can force temp variables:

FOO array[I][J][K];
...
FOO *atmp;
FOO btmp;
...

atmp = &(array[h][s][l]);
btmp = bigexpr;
UPMAX(*atmp,btmp);

As for the lousy human engineering in requiring extra blanks in certain
expressions, don't we have that already in C, e.g.:

a = b/*c;	/* did this mean divide b by *c, or to start a comment? */ ;
a=*b;		/* compiler complains about "ambiguous assignment" here */
-- 
 -------------------------------    Disclaimer:  The views contained herein are
|       dan levy | yvel nad      |  my own and are not at all those of my em-
|         an engihacker @        |  ployer or the administrator of any computer
| at&t computer systems division |  upon which I may hack.
|        skokie, illinois        |
 --------------------------------   Path: ..!{akgua,homxb,ihnp4,ltuxa,mvuxa,
						vax135}!ttrdc!levy



More information about the Comp.lang.c mailing list