[comp.lang.c] priorities of = and == revisited

nevin1@ihlpf.ATT.COM (00704A-Liber) (01/23/88)

In article <1175@ark.cs.vu.nl> maart@cs.vu.nl (Maarten Litmaath) writes:
>Allright, maybe I was a bit hasty in putting aside the 'backward compatibility'
>argument. Further, it's generally good to give assignment low priority, I
>guess. But on the other hand, as Tom Truscott mentioned, "C converted from
>x =OP y to x OP= y without too much hassle", so why not enhancing the
>language further ?

This would not be an enhancement!  The reason that
x =OP y was changed to x OP= y was to avoid ambiguous statements in C. Example:
Does x=*y mean 'assign what y points to to x' or does it mean 'multiply x by y
and assign it to x'?  (I don't think whitespace is required between operators.)

One of the reasons that the precedence of assignment is put low is because the
operators above it all produce results which can be assigned to a var.  (If you
put assignment above bitwise or, for example, x = a | b would mean (x = a) | b
instead of x = (a | b).)  This leads to consistency in use, which most people
would agree makes it easier to remember and hence easier to use (though in some
circumstances more verbose).
-- 
 _ __			NEVIN J. LIBER	..!ihnp4!ihlpf!nevin1	(312) 510-6194
' )  )				"The secret compartment of my ring I fill
 /  / _ , __o  ____		 with an Underdog super-energy pill."
/  (_</_\/ <__/ / <_	These are solely MY opinions, not AT&T's, blah blah blah

trt@rti.UUCP (Thomas Truscott) (01/25/88)

The fact is that C did convert from =OP to OP= without much
hassle, ambiguities notwithstanding.
The key thing that made it possible is that

	The C compiler can warn of hazardous/ambiguous situations

It is the fact that the C compiler can warn of hazardous/ambiguous
operator precedences that makes me believe we can change
C precedence (in those few places where it makes sense)
without too much hassle.

Whether or not a new set of rules becomes permitted
(it is probably too late to force a switchover)
I sure wish compilers would warn me of dubious situations.
	Tom Truscott

dricej@drilex.UUCP (Craig Jackson) (01/28/88)

In article <1175@ark.cs.vu.nl> maart@cs.vu.nl (Maarten Litmaath) writes:
>Allright, maybe I was a bit hasty in putting aside the 'backward compatibility'
>argument. Further, it's generally good to give assignment low priority, I
>guess. But on the other hand, as Tom Truscott mentioned, "C converted from
>x =OP y to x OP= y without too much hassle", so why not enhancing the
>language further ?

Don't forget that the change of x =OP y to x OP= y was made during C's
youth, when there were few implementations and relatively few programs
written in C.  (Mostly just the Unix distribution itself.)  And both
forms were allowed for many years.  To make an incompatible changes,
where you could not continue the old forms for compatibility, today 
is almost impossible.

Face, if you really wanted to rearrange == vs = you needed to make some
strong arguments to DMR about 15 years ago.


-- 
Craig Jackson
UUCP: {harvard!axiom,linus!axiom,ll-xn}!drilex!dricej
BIX:  cjackson

nevin1@ihlpf.ATT.COM (00704a-Liber) (01/28/88)

In article <1988@rti.UUCP> trt@rti.UUCP (Thomas Truscott) writes:
>The fact is that C did convert from =OP to OP= without much
>hassle, ambiguities notwithstanding.
>
>It is the fact that the C compiler can warn of hazardous/ambiguous
>operator precedences that makes me believe we can change
>C precedence (in those few places where it makes sense)
>without too much hassle.

The =OP to OP= was a syntactic change, while changing the operator precedences
would be a SEMANTIC change.  Yes, tools can be written to go through and
parenthesize code which uses the old precedence, but this is not the point (C
programmers can write tools to do anything :-)).  The rules make sense as they
are now (at least to me); changing them may make sense to you but will be
nonsense to many others.
-- 
 _ __			NEVIN J. LIBER	..!ihnp4!ihlpf!nevin1	(312) 510-6194
' )  )				"The secret compartment of my ring I fill
 /  / _ , __o  ____		 with an Underdog super-energy pill."
/  (_</_\/ <__/ / <_	These are solely MY opinions, not AT&T's, blah blah blah