Assignment in test: OK?

Jon H. LaBadie jon at jonlab.UUCP
Thu Sep 20 01:29:24 AEST 1990


In article <14316:Sep1511:00:2390 at kramden.acf.nyu.edu>, brnstnd at kramden.acf.nyu.edu (Dan Bernstein) writes:
> 
> Splitting off := for assignments that do return a value is enough.
> People will use = except in situations like a = b := c := d, so they'll
> be used to = for equality. When they write if (a = b), the compiler will
> catch the mistake.
> 
> Bruce, am I right in thinking that =/:=/== would satisfy you?

How long will this continue?
Now we should think "gee, do I want THIS assignment to yield a value
or simply do an assignment?".

BTW Dan, I think it should be yield, or evaluate to, a value, not
         return a value.

One of the many virtues of C is that assignment IS an operator and
DOES yield a value.

If you spend countless hours debugging code because of mistyping the
assignment operator when you meant the equality comparison operator,
then get a copy of "ccheck".  I think it was posted to c.s.m.  It
reports (does not say it is wrong) instances of assignments in
contexts where comparison is expected.  Use it as religously as
you do lint.  It will reduce your debugging dramatically.

This part of the language is not broken, don't try to fix it.

Jon


-- 
Jon LaBadie
{att, princeton, bcr, attmail!auxnj}!jonlab!jon



More information about the Comp.lang.c mailing list