ambiguous ?

David Goodenough dg at lakart.UUCP
Sat Oct 28 02:43:36 AEST 1989


exspes at gdr.bath.ac.uk (P E Smee) sez:
> .....  Algol may have this right,
> they offer two sets of logical operators:  AND and OR which do not short
> circuit; and ANDTHEN and ORELSE which do.  This gives the programmer total
> control, and might be worth considering for some future version of C or
> a C offspring.  Both are useful, and making either from the other in a
> language which only supports one is fiddly at best.

However, those of us that know De Morgan's laws can get by very neatly
with ! & | and a couple of preprocessor macros for non-short circuiting
operators.

#define and(x, y) (!((!(x)) | (!(y))))
#define or(x, y)  (!((!(x)) & (!(y))))

This does rather assume that your optimizer is up to the job, but then
that's a whole other thread. Also, as someone once said "Never sacrifice
clarity for efficiency" (gets +6 ring of fire resistance ready :-) )
-- 
	dg at lakart.UUCP - David Goodenough		+---+
						IHS	| +-+-+
	....... !harvard!xait!lakart!dg			+-+-+ |
AKA:	dg%lakart.uucp at xait.xerox.com			  +---+



More information about the Comp.lang.c mailing list