What should be added to C

Frank Adams franka at mmintl.UUCP
Fri May 30 21:58:19 AEST 1986


In article <852 at bentley.UUCP> kwh at bentley.UUCP writes:
>>>o There should be an option to flag statements of the form if (v = e) ...
>>>(Actually, I wouldn't be averse to a coding standard which forbade such
>>>things, in favor of if (v = e, v) ...)
>
>Urgh.  Are you talking about removing the assignment-has-a-value feature
>completely, or a special case for "if (v = e)"?  (I always write this as
>"if ((v = e) != 0)" to make it clear that I didn't mean "if (v == e)".)
>
>Actually, the main argument in favor of valued assignment is to allow such
>things as "while ((c = getchar()) != EOF)".  This really doesn't look so
>bad with the unvalued assignment "while (c = getchar(), c != EOF), so it
>may not be such a bad idea.

Actually, I was not proposing removing the assignment-has-a-value feature
anywhere (although I would not put it into a new language I was designing).
The proposal was that it be avoided in if's (and probably while's as well)
as a coding standard.  That is, it would be legal, but not recommended.

In fact, I only use the results from an assignment in two cases.  One is to
assign the same value to multiple variables, and the other is in the if/while
case under discussion here.  (Yes, I also normally use "if ((v = e) != 0)").
I may stop using it in this latter case, in favor of the comma operator as
described above.

Frank Adams                           ihnp4!philabs!pwa-b!mmintl!franka
Multimate International    52 Oakland Ave North    E. Hartford, CT 06108



More information about the Comp.lang.c mailing list