Newsgroups: comp.arch
Path: utzoo!henry
From: henry@utzoo.uucp (Henry Spencer)
Subject: Re: Shifting question
Message-ID: <1988Jul21.200837.19181@utzoo.uucp>
Organization: U of Toronto Zoology
References: <705@bnr-rsc.UUCP> <440@softway.oz>
Date: Thu, 21 Jul 88 20:08:37 GMT

In article <440@softway.oz> stephenf@softway.UUCP (Stephen Frede) writes:
>Contrary to the other two follow-ups I've seen (when will
>people learn not to react without thinking), yes you do have a
>valid complaint. The C language (both K+R and X3J11)
>guarantees that X >> n is a logical shift, with 0 padding on
>the left, when X is an unsigned quantity, as it is in this
>case. It is only when X is not unsigned, that a right shift is
>implementation dependant.

Sorry, Stephen, but in this case you're the one who's reacting without
thinking.  The first paragraph of the Semantics subsection of section
3.3.7 of the second-public-comment draft states:

	If the value of the right operand... is greater than or equal
	to the width in bits of the... left operand, the behavior is
	undefined.

This applies to *all shifts*, not just signed ones.  Somewhat further
down we find another statement to the effect that right shifts of
negative signed numbers give implementation-defined values.

Note that these two statements don't say quite the same thing, either:
right shift of a negative signed number yields an implementation-defined
value, that is, a well-defined value that depends on the implementation in
a way that the implementation is required to document, while shift-all-bits
yields undefined behavior, that is, it can do anything it pleases.
-- 
Anyone who buys Wisconsin cheese is|  Henry Spencer at U of Toronto Zoology
a traitor to mankind.  --Pournelle |uunet!mnetor!utzoo! henry @zoo.toronto.edu
