Multiple assignments

Frank Adams franka at mmintl.UUCP
Mon May 12 15:23:17 AEST 1986


In article <797 at bentley.UUCP> kwh at bentley.UUCP writes:
>In article <501 at brl-smoke.ARPA> rbj at icst-cmr (Root Boy Jim) writes:
>>And as someone pointed out, assignments return a value too, so should we
>>cast them to void as well?  Oh yeah, assignment is `different'.
>
>Actually, this does bother me somewhat.  I think I prefer the idea that
>values should be used or explicitly discarded, as in forth.  (Not that forth
>has any error checking!)  No, I'm not suggesting that lint should complain
>about assignments, or that C should have a different notation for assignments
>that are being pipelined into another expression.  Just waiting for the next
>generation of languages.

This bothers me somewhat too.  I do have a suggestion for how to deal with
it: have a "multi-assignment" operator.  Supposing that "$" is being used
for this operator, then to set both "a" and "b" to zero, one would write
"a $ b = 0", rather than "a = b = 0", as C does.  This has the disadvantage
that it cannot be used where the result of the assignment is used
immediately in a calculation (e.g., "a = 2 * b = sqrt(c)").  On the other
hand, if your language supports argument passing by address, it permits an
output argument to be multiply assigned; something which
assignment-with-value does not support.

I am not recommending that this be put into C.  It is an idea for new
languages.  Accordingly, I have directed follow-ups to net.lang instead of
net.lang.c.

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