Right shift vs. divide
Utah
jj at nrcvax.UUCP
Wed Dec 25 03:37:21 AEST 1985
In article <974 at brl-tgr.ARPA> Schauble at mit-multics.arpa (Paul Schauble) writes:
>
>BTW, is >> defined to be a sign-extended shift or a zero extended shift
>and under what circumstances.
>
> Paul
> Schauble @ MIT-Multics
The way that I interpreted this when generating machine code (68000) for a >> X
was that if a was 'signed' (char, short, int, and long in our implementation)
the compiler generated an arithmetic shift. If a was 'unsigned'
(unsigned char, unsigned short, unsigned int, unsigned long), it generated
a bitwise (logical?) shift.
BTW, most C compilers I have seen do not fold the following constant expression
correctly: ((unsigned long)0xFFFFFFFF) >> 1 /* or anything w/sign bit on */
Seems like the constant folding function in the compiler only does arithmetic
shifts.
-------------------------------------------------------------------------
Jeff Jennings Network Research Corp.
ihnp4!nrcvax!nrcutah!jj 923 Executive Park Drive Suite C
ucbvax!calma!nrcvax!nrcutah!jj Salt Lake City, Utah 84117, U.S.A.
{sdcsvax,hplabs}!sdcrdcf!psivax!nrcvax!nrcutah!jj (801) 266-9194
More information about the Comp.lang.c
mailing list