Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!mnetor!uunet!husc6!think!ames!sunybcs!ugfailau
From: ugfailau@sunybcs.uucp (Fai Lau)
Newsgroups: comp.lang.c,comp.sys.ibm.pc
Subject: Re: What's Wrong here?
Message-ID: <6930@sunybcs.UUCP>
Date: Tue, 1-Dec-87 20:32:19 EST
Article-I.D.: sunybcs.6930
Posted: Tue Dec  1 20:32:19 1987
Date-Received: Sat, 5-Dec-87 01:24:58 EST
References: <278@westmark.UUCP> <6755@brl-smoke.ARPA> <6855@sunybcs.UUCP> <9562@mimsy.UUCP>
Sender: nobody@sunybcs.UUCP
Reply-To: ugfailau@joey.UUCP (Fai Lau)
Organization: SUNY/Buffalo Computer Science
Lines: 57
Xref: mnetor comp.lang.c:5679 comp.sys.ibm.pc:10682

In article <9562@mimsy.UUCP> chris@mimsy.UUCP (Chris Torek) writes:
>In article <6855@sunybcs.UUCP> ugfailau@sunybcs.uucp (Fai Lau) writes:
>> .....
>>be shifted "on". That is, when the sign bit is turned on as
>>a result of bit shifting, it can not be turned off again, ....
>
>This may be true for left shifts, although I doubt it.  It is
>probably true for right shifts.
>
	It *is* true for every version of C I've ever worked on.
I don't know about the machines. I made a mistake by not mentioning
the shift is "left" shift. I am not sure know about right shift.
The result puzzles me too. I remember I've worked on bit shifts
on C before, it took me a lot of agony to realize this characteristic.

>>	In the [original example], a 16 bit word is overshifted.
>>What's left is a word with *only* the left most bit, the sign
>>bit, turned on. This bit pattern represents an integer
>>value of -65536 (I don't want to go into how the *value*
>>of a negative number is represented).
>
>Nonsense.  The pattern 0x8000 as a signed two's complement 16
>bit value represents -32768.
>
	True. I forgot the positive half. 16 bits can only represent
65536 integers. With 32767 positive integers and one 0, there are
only 32768 negative integers. But the misinterpretation of the
16th bit still holds true.

>
>>	The operation is not undefine.
>
>Again, nonsense.  The result is undefined *in C*.  No doubt the
>operation on any given system is predictable (though possibly with
>difficulty: a compiler is free to implement underflow by replacing
>the value with the time of day, or the apparent diameter of the
>lit region of the moon, or soemthing equally absurd).  Most will
>ignore the underflow and change 0x80000000 to 0x7fffffff; others
>may trap and give you a core dump.
>-- 
	It is all in how you see it. If you know the behavior
of your machine, you can no doubt use the over flow characteristic
as a defined function. A function which returns an undefined result
in certain input circumstances can be considered defined in all
input circumstanc if the undefined output is predictable and
is indeed included in the set of output which is considered,

$$$filler
$$$filler is a necessary evil
$$$filler
$$$filler
???Enough???

Fai  Lau
SUNY at Buffalo (The Arctic Wonderland)
UUCP: ..{mit-ems|watmath|rocksanne}!sunybcs!ugfailau
BI: ugfailau@sunybcs