Precedent for use of =

Chris Torek chris at umcp-cs.UUCP
Wed Jul 9 14:50:15 AEST 1986


In article <6056 at sri-spam.ARPA> argv at sri-spam.UUCP (AAAARRRRGGGGv) writes:
>this construct ... [if (lvalue = rvalue) { ...] is quite common in C,
>altho good programmers comment that they know what they're doing here...
>for example, my favorite:
>
>main(argc, argv)
>char **argv;
>{
>    char *prog_name, *rindex();
>
>    if (prog_name = rindex(*argv, '/'))  /* find last '/' in argv[0] */
>	prog_name++; /* set prog_name to string following last '/' */
>    else prog_name = *argv; /* program was exec-ed from same dir or in PATH */
>    /* etc... */

I have come to favour

	if ((prog_name = rindex(*argv, '/')) != NULL)
		...

One of these years I will get around to installing Arthur Olson's
lint code that gripes about assignments in conditional contexts.
Adding the `!= 0' is not difficult and demonstrates your `true
intention' quite well.

>I would say that C was designed more robustly simply because you can
>do the above [if (v = e)] whereas PASCAL won't let you.

I think the proper word here is `orthogonal'.  Actually, I have a
feeling there is an even better word (no not *that* word :-) ), but
I cannot recall it now.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 1516)
UUCP:	seismo!umcp-cs!chris
CSNet:	chris at umcp-cs		ARPA:	chris at mimsy.umd.edu



More information about the Comp.lang.c mailing list