Path: utzoo!utgpu!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!rutgers!apple!kchen From: kchen@Apple.COM (Kok Chen) Newsgroups: comp.lang.c Subject: Re: assigning an integer to ... Message-ID: <22581@apple.Apple.COM> Date: 20 Dec 88 17:25:04 GMT References: <1911@pembina.UUCP> Organization: Apple Computer Inc, Cupertino, CA Lines: 25 In article <1911@pembina.UUCP> lake@alberta.UUCP (Robert Lake) writes: > int i; > short j = 1; > i = -(unsigned short)j; >If I run this program on a VAX 11/780 using 4.3 BSD, I obtain -1 as the >answer. However, if I run this on a SUN using SUN OS 3.5, I obtain 65535 >as the answer. Who is right? ... From K&R-I, arithmetic operators (including unary ones) are supposed to work on longs, no? I would have compiled the line of code into: load j sign extend to a long negate (cast to type of i) store i This means BSD is the more correct one, based on K&R-I. But, why would one have written such a contorted line of code in real life? Or, is this yet another attempt at breaking compilers? :-) Kok Chen {decwrl,sun}!apple!kchen Apple Computer, Inc.