Assignment in test: OK?

Al Dunbar userAKDU at mts.ucs.UAlberta.CA
Thu Sep 13 11:08:06 AEST 1990


In article <BURLEY.90Sep12073323 at world.std.com>, burley at world.std.com (James C Burley) writes:
>In article <18326 at ultima.socs.uts.edu.au> jeremy at sinope.socs.uts.edu.au (Jeremy Fitzhardinge) writes:
>
>   >> BTW, if I ever write a new C-like language, ":=" will be the assignment
>   >> operator, "==" the comparison operator, and "=" totally invalid!  Although
>
>   If you are going to prevent assignment in a conditional, you are preventing
>  <stuff deleted>>
>I doubt anyone could seriously disagree with an argument that it would have
>saved much unnecessary debugging effort if, from the beginning, K&R had
>realized that making "=" an assignment OPERATOR (thus allowing it to work as
>an operator inside an expression) was a mistake -- it meant they had to make
>"==" the comparison operator, which no other language I know of ever had to,
>because others do not allow assignment as an operator.  Given that most people
>would at one point or another accidentally use "=" instead of "==", it would
>have been great (20-20 hindsight) if they'd realized this from the beginning
>and made ":=" or some such thing the assignment operator, leaving "=" out of
>the picture.  .....
 
Originally being a Fortran person, the ":=" assignment operator
always seemed to me an abomination, both in terms of style and
inconvenience. Now that I spend more time with C, the =/==
problem (to say nothing of &/&& etc) hasn't bothered me as much
as I once thought it would. This isn't to say that I haven't made
the dreaded mistake, of course. But that's not my point. My point
is that I don't recall anyone confusing the assignment and
comparison operators in (at least pre-90) Fortran:
 
A .EQ. B + C
IF(A = D) GOTO 999
 
The reason is twofold: a) the compiler doesn't allow either
substitution, and b) '=' and '.EQ.' do not look at all alike.
It is just too bad that there are not enough special punctuation
marks to allow unambiguous use of single character operators for
such things as ==, <=, &&, etc.
 
-------------------+-------------------------------------------
Al Dunbar          |
Edmonton, Alberta  |   this space for rent
CANADA             |
-------------------+-------------------------------------------



More information about the Comp.lang.c mailing list