Precedent for use of =

rmarti at sun.UUCP rmarti at sun.UUCP
Tue Jul 8 03:44:55 AEST 1986


> Everybody keeps guessing at the reasons for the use of = for asignment
> and == for equality tests.  How about a different angle: how many times
> in a program do you assign something versus how many times you compare things?
> 
> [ ... ]
> 
> Maybe Mssrs. Kernighan and/or Ritchie would like to give some input on
> their reasons of choice.
> -------

They already did.  Let me quote K&R, p.17:

  The double equals sign == is the C notation for "is equal to" (like
  Fortrans's .EQ.).  This symbol is used to distinguish the equality
  test from the single = used for assignment.  Since assignment is about
  twice as frequent as equality testing in typical C programs, it's
  appropriate that the operator be half as long.

Personally, I still prefer := for assignment and = for equality over =
and ==.  I also think that the keystroke argument is ridiculous (flames
to /dev/null).  The problem with = and == is further aggravated by the
fact that in C an assignment is an expression and not a statement, so
that code like

  if (i = 0) {
    /* do something */
  }
  else {
    /* do something else */
  }

is legal C and usually  /* does something else */   than you expected  :-)

Despite that, I would never call Messrs K&R idiots, as Niklaus Wirth has
been labeled in a recent message (not the one I am responding to):
I think both C and Pascal have been reasonable designs of programming
languages and important contributions to the computing community.
-- 

Robert Marti, Sun Microsystems, Inc.

UUCP: ...{cbosgd,decvax,decwrl,hplabs,ihnp4,pyramid,seismo,ucbvax}!sun!rmarti
ARPA: rmarti at sun.com



More information about the Comp.lang.c mailing list