[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
## Re: Arithmetic Shift

**From**: |
Paul Eggert |

**Subject**: |
Re: Arithmetic Shift |

**Date**: |
Fri, 10 Dec 2010 07:38:09 -0800 |

**User-agent**: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.13) Gecko/20101208 Thunderbird/3.1.7 |

On 12/10/2010 03:54 AM, Andrew W. Nosenko wrote:
>*> > Doesn't this suffice, without dragging Autoconf into it?*
>*> >*
>*> > #if -1 >> 1 == -1*
>* No. It won't work. Your preprocessor directive checks behavior of*
>* the preprocessor (/bin/cpp for example) that may have nothing with the*
>* behavior of the compiler and behavior of the code generated by*
>* compiler.*
If that is the issue, then even Autoconf won't work.
Nothing in the C standard says that -1 >> 1 must evaluate to
anything in particular; the result is implementation-defined,
which means that it has to be *something* (there can't be
a core-dump), and it has to be documented, but it can
depend on the word size or even (in theory) the phase
of the moon. For example:
return (-1 >> 1) == (-1L >> 1);
might return 0.
The usual assumption, of course, is that the compiler picks
one interpretation of >> and sticks with it. If that is
true, then "#if -1 >> 1 == -1" works, and any preprocessor
that behaves differently from the compiler is simply buggy.
If it is false, then code should not depend on any consistent
result from shifting negative values right.

**Arithmetic Shift**, *Mike Gibson*, `2010/12/09`
**Re: Arithmetic Shift**, *Philip Herron*, `2010/12/09`
**Re: Arithmetic Shift**, *Paul Eggert*, `2010/12/09`
**Re: Arithmetic Shift**, *Mike Gibson*, `2010/12/09`
**Re: Arithmetic Shift**, *Andrew W. Nosenko*, `2010/12/10`
**Re: Arithmetic Shift**, *Ben Pfaff*, `2010/12/10`
**Re: Arithmetic Shift**, *Dave Goodell*, `2010/12/10`
**Re: Arithmetic Shift**, *Ben Pfaff*, `2010/12/10`
**Re: Arithmetic Shift**, *Paul Eggert*, `2010/12/10`
**Re: Arithmetic Shift**, *Andrew W. Nosenko*, `2010/12/11`
**Re: Arithmetic Shift**, *Paul Eggert*, `2010/12/11`