Path: utzoo!utgpu!attcan!uunet!lll-winken!lll-tis!ames!umd5!brl-adm!brl-smoke!gwyn From: gwyn@brl-smoke.ARPA (Doug Gwyn ) Newsgroups: comp.lang.c Subject: Re: Shifting question Message-ID: <8252@brl-smoke.ARPA> Date: 29 Jul 88 02:22:34 GMT References: <705@bnr-rsc.UUCP> <11556@steinmetz.ge.com> <60290@sun.uucp> <1818@spar.SPAR.SLB.COM> <11592@steinmetz.ge.com> Reply-To: gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 14 In article <11592@steinmetz.ge.com> davidsen@crdos1.UUCP (bill davidsen) writes: >| > ...If the value of the right operand is negative or is greater than or >| > equal to the width in bits of the promoted left operand, the behavior >| > is undefined. > So you have to build in an explicit check in every program, comparing >the shift with the size of the item. No; the vast majority of shifts in C applications do not require the check. However, if the language guaranteed the behavior you want it to, then on many architectures a far larger percentage of shifts would have to perform the check (in the compiler-generated code). This is one of the many cases where C is deliberately permissive in order to allow a better fit to the hardware. It is of course not what an "ideal" programming language would do, where "ideal" includes the notion of suitable hardware.