Re: Arithmetic Shift

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

_______________________________________________
Autoconf mailing list
Autoconf@xxxxxxx
http://lists.gnu.org/mailman/listinfo/autoconf


[Index of Archives]     [GCC Help]     [Kernel Discussion]     [RPM Discussion]     [Red Hat Development]     [Yosemite News]     [Linux USB]     [Samba]

  Powered by Linux