Precedent for use of =

mangoe at mimsy.umd.edu mangoe at mimsy.umd.edu
Tue Jul 15 16:31:21 AEST 1986


The reasons all really boil down to optimization.  The only reason I can see
to prefer (a=b) over ((a=b)!=NULL)  (why did C have to perpetuate the PL/I
mistake on the not-equals operator, anyway?) is efficiency, and this isn't
exactly a difficult optimization to do mechanically.  I can see that it is
useful for some applications to be able to write in what is essentially a
high level language containing an assembler, but I don't for a minute believ
that it is a virtue.  I also don't believe that the C method is the only way
to have assignments in expressions and still keep "=" for both purposes.  One
of PL/I's few virtues is that it recognizes that equality and assignments are
both reasonably common, but that assignments in expressions are relatively
rare.  So it has a special "assignment-with-value" operator.  If it is insisted
that there is a separate boolean type, then most of the errors in this 
sort of system can be flagged and corrected.

I've been looking at 4.3 code, particularly for the Sun.  There are plenty of
places where pointers are used indifferently as pointers to structures and
as pointers to arrays.  There is code which relies on ints and pointers being
the same size.  There is code which relies on successive declarations being
stored contiguously and in order.  Code which relies on NULL equalling zero
is omnipresent.  All this leads me inescapably to the conclusion that C was
designed to allow programmers to violate the rules which everyone else is
busily putting into their languages to protect themselves.

I have to use C, but I'm not at all happy with what itclaims as features.

CGW



More information about the Comp.lang.c mailing list