warning: ambiguous assignment: assignment op taken 
Author Message
 warning: ambiguous assignment: assignment op taken

Consider this program:

int a=4, b=5;




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 fif{*filter*}-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.

Mon, 17 Aug 1992 10:27:00 GMT  
 warning: ambiguous assignment: assignment op taken

        [complaint about (a=-b;) != (a = -b;) deleted.]

    Think, at the time the compilers you are complaining about where originally
written, the (a =- b;) construct was still a problem. Old code was still being
recompiled to run under new machines, I'd rather have a compiler complain about
a possible problem, than to have it compile without a single complaint and have
the program give me an incorrect result. With or without warning messages, which
is easier to debug?

    By the way, The version of compiler you are using must be pre-4.0. I compiled
your program under SunOS 4.0.1 and it did not complain, and it did give me the
correct answer of:

a=-5    b=5.

    Editing the source to remove the ambiguity ( i.e. change (a=-b;) to (a = -b;))
resolves the problem under SunOS 3.4 and 3.5.  Atleast with the warning messages
you know which lines to edit.

Matthew Lee Stier                         |
Sun Microsystems ---  RTP, NC  27709-3447 |        "Wisconsin   Escapee"
uucp: { sun, mcnc!rti }!sunpix!matthew    |
phone: (919) 469-8300 fax: (919) 460-8355 |

Mon, 17 Aug 1992 16:33:00 GMT  
 [ 2 post ] 

 Relevant Pages 

1. Unexpected warning on _variant_t to bool assignment

2. C4244 warnings ULONG_PTR to DBBYTELENGTH assignment

3. Warning: Assignment of read-only member?

4. warning: possibly incorrect assignment

5. Pointer assignment warnings

6. Compiler warning for assignment in if statement?

7. BUG ? : warning C4706: assignment within conditional expression

8. accidental assignment warnings

9. Getting warnings for long to short assignments (how)?

10. SHFileOperation(&op);op.pFrom

11. auto_ptr assignment broken in 7.1?

12. Icon assignment


Powered by phpBB® Forum Software