warning: ambiguous assignment: assignment op taken

Math Student from Hell entropy at pawl.rpi.edu
Wed Mar 8 20:27:03 AEST 1989


Consider this program:

main()
{
int a=4, b=5;

a=-b;

printf("a=%d\tb=%d.\n",a,b);
}

When I compile this on our Sun 3/50 I get these warning messages:
"foo.c", line 6: warning: ambiguous assignment: assignment op taken
"foo.c", line 6: warning: old-fashioned assignment operator

Which means that the a=-b was interpreted as a =- b and not as a = -b.
And of course the output is:
a=-1	b=5.

And when I compile on out Sequent Balance 21000 (V3.0.14 DYNIX) I get
no warning messages, but the same bogus output anyway.

Now, K&R First Edition (1975?) says that a =- b is obsolete and that the
correct form is a -= b, because it avoids this very ambiguity.

I gave two questions:

1) Why did Sun (and Sequent, and anyone else who did it) write their
   compiler to make the *wrong* decision on this fifteen-year-old
   mistake?  If =- was obsolete in the time of K&R1, why do these
   recent compilers assume that =- is what was intended in the
   ambiguous code?

2) What does the ANSI standard have to say about the old-fashioned
   assignment operators?

Email replies only, please; I will summarize.

 In some sense, a stochastic process can do better; at least it has a chance.
S. M-J. C. Dominus 	entropy at pawl.rpi.EDU	     entropy at rpitsmts (BITnet)



More information about the Comp.lang.c mailing list