Additions to C - range checking

rb at ccird1.UUCP rb at ccird1.UUCP
Tue Jun 24 13:58:55 AEST 1986


One common reference that kills is the old "is this in range"
test.

typically, this is written:

if((5<a)&&(a<50)) do_something(a);

suppose instead of a, you use a->b->c->d, all that pointer
arithmetic gets done twice? (maybe it is optimized but its harder
to read).

How about:

if (5<a<50) do_something(a);

this would currently be interpreted as

if((5<a)<50).  since, if a=100 (5<a) evaluates to 1 and 1<50, it
is true for any number greater than 5 right?

this can be real useful for pre-checking an array bounds, a
int (f[])(); type switch, and even skipping over a case statement.

Is this impossible to parse?



More information about the Comp.lang.c mailing list