[Top][All Lists]

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

Re: Arithmetic Shift

From: Andrew W. Nosenko
Subject: Re: Arithmetic Shift
Date: Fri, 10 Dec 2010 19:17:27 +0200

On Fri, Dec 10, 2010 at 17:38, Paul Eggert <address@hidden> wrote:
> 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.

Excuse me?  Why do you think that preprocessor should match the
behavior of compiler???

You may assume that system's preprocessor match system's compiler.
It's a dangerous assumption, but OK, assume that it's true.

Now install some additional compiler.  For example, Clang or ICC in
addition to the yourt system's GCC.

Why, why system's /usr/bin/cpp that come from GCC should match to
Clang's behavior?  Or ICC's behavior?  Remember: Accordingly to your
logic, if it doesn't match, then it is invalid.  Why?  And if ICC and
Clang interpret -1 >> 1 differently, then it renders GCC's CPP
constantly invalid?

Excuse me again, but your logic is flawed.

Preprocessor is preprocessor.  It may be from the same cup as
compiler.  And sometime even is.  But it's not universally true.
Therefore, you should always keep in mind that preprocessor and
compiler are two different things that may come even from different
vendors.  And you cannot guess compiler's behavior from the behavior
of preprocessor or behavior of preprocessor from behavior of compiler.
 BTW, the same true for assembler and linker.

Andrew W. Nosenko <address@hidden>

reply via email to

[Prev in Thread] Current Thread [Next in Thread]