"str*cmp()" ain't Boolean (was Re: v18i058: mush - Mail User's Shell, Part01/22)

Martin Weitzel martin at mwtech.UUCP
Wed May 8 22:42:04 AEST 1991


In article <1991May7.012817.4395 at rlgvax.Reston.ICL.COM> scc at rlgvax.Reston.ICL.COM (Stephen Carlson) writes:

>#define streq !strcmp
>#define strneq !strncmp

What about:

#define strdiff strcmp
#define strndiff strncmp

	if (strdiff("foo", "bar") == 0) /* if there is no difference ... */

	if (!strdiff("foo", "bar"))	/* if there is no difference ... */

	if (strdiff("foo", "bar"))	/* if there IS a difference ... */

The nice thing with this approach is that you can almost blindly convert
any source which does NOT use this style: %s/\<strcmp\>/strdiff/g.

The other nice thing is that, after you get tired of changing the sources
written by others, sooner or later your eyes and brains get trained simply
to READ any "strcmp" you encounter as "strdiff" ...

(There's also a minor nitpick with the solution of the original poster:
"*neq" tastes slightly as "not equal" to some programmers. I admit that
"*ndiff" could also be misinterpreted in this way, but IMHO "neq" has
made it into some computer languages, "ndiff" hasn't.)
-- 
Martin Weitzel, email: martin at mwtech.UUCP, voice: 49-(0)6151-6 56 83



More information about the Comp.lang.c mailing list