Path: utzoo!utgpu!watmath!clyde!att!occrsh!uokmax!rmtodd From: rmtodd@uokmax.UUCP (Richard Michael Todd) Newsgroups: comp.unix.wizards Subject: Old-fashioned assignment operators (was Re: braces Message-ID: <2155@uokmax.UUCP> Date: 16 Dec 88 22:53:37 GMT References: <9076@smoke.BRL.MIL> <14020049@hpisod2.HP.COM> <212@UNIX386.Convergent.COM> <2151@uokmax.UUCP> Reply-To: rmtodd@uokmax.UUCP (Richard Michael Todd) Organization: University of Oklahoma, Norman, OK Lines: 53 In article <2151@uokmax.UUCP> randy@uokmax.UUCP (Longshot) writes: >As an interesting aside, the cc here on our Multimax will generate warnings for >lines like: > > x=-y; /* x = -y or x =- y? */ > >In other words, and math operator that can be combined with = can produce an >error. This will happen with +,-, *, and any others that fit the bill. Now, I >have yet to hard-test it to see which case it generates. Has anyone had >similiar messages, and checked further? Script started on Fri Dec 16 16:06:15 1988 % cat foo.c main() { int x,y; x = 3; y = 4; x=-y; printf("%d\n",x); } % cc foo.c "foo.c", line 5: warning: old-fashioned assignment operator % a.out -1 % ^D script done on Fri Dec 16 16:06:40 1988 It seems to be interpreting "=-" as "-=". The message warns of an "old-fashioned" assignment operator. There's an interesting bit of history here. Back around 6th Edition Unix (I think) the augmented assignment operators in C were written as =+, =-, etc, not "+=" like we do today. Unfortunately that caused an ambiguity problem: does x=-y mean x = -y or x =- y? That, I believe, is why the operator syntax was changed circa 7th Edition. The compilers were changed to accept the old syntax "=-" but issue a warning. The question I have is, what exactly *is* the correct interpretation of x=-y in modern C? As mentioned before, the Encore cc interprets it as augmented assignment. The compiler I use on my PC interprets it as assigning -y to x. Which interpretation is right? What does the ANSI C standard say about this? Of course, the existence of compilers that interpret this line differently means that if you want your code to be portable, you *must* include proper spaces; if you want to assign -y to x, you must say "x = -y" if you want your code to work everywhere. Finally, I question why this business of checking for old-fashioned assignment operators is still in Unix C compilers. After all, V7 came out around 10 years ago! Does anyone really have around any code that hasn't been converted to the new syntax by *now*? -- Richard Todd Fido:1:147/1 USSnail:820 Annie Court,Norman OK 73069 Try one of these: rmtodd@chinet.uucp, rmtodd@killer.dallas.tx.us, rmtodd@uokmax.ecn.uoknor.edu or ...!sun!texsun!uokmax!rmtodd. "MSDOS is a Neanderthal operating system" - Henry Spencer