[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Arithmetic Shift
From: |
Andrew W. Nosenko |
Subject: |
Re: Arithmetic Shift |
Date: |
Sat, 11 Dec 2010 16:16:25 +0200 |
On Fri, Dec 10, 2010 at 22:03, Paul Eggert <address@hidden> wrote:
> On 12/10/10 09:33, Ben Pfaff wrote:
>> Is it even necessary to drag the preprocessor into it?
>>
>> if (-1 >> 1 == 1)
>
> Yes, good point: in many cases that suffices,
> and if it works it's typically better to avoid the
> preprocessor.
>
> On 12/10/10 09:17, Andrew W. Nosenko wrote:
>
>> Why do you think that preprocessor should match the
>> behavior of compiler???
>
> Because in practice, when they don't, Bad Things Happen,
> this being one of the least of the problems. Generally
> speaking, it's not worth worrying about mismatches when
> one mixes a preprocessor from source A (or for machine A)
> with a compiler from source B (or for machine B).
>
> For example, if LONG_MAX from the preprocessor is less than the
> actual maximum long int value supported by the compiler, then
> it's better to treat the weird compiler+preprocessor behavior
> as being buggy, and to fix the bug rather than contort the
> code with some complicated Autoconf test. Alternatively,
> if it's easy, it's even better to modify the code so that
> it works regardless of whether LONG_MAX is truly the maximum
> long int value; this avoids the need for any Autoconf
> or other test.
You mismatch the preprocessor function (find the LONG_MAX macro and
replace it by it's definition found somewhere in header) with the
function of compiler (inject proper search path to the preprocessor if
compiler redefines some system's headers).
>
> The situation with -1 >> 1 is similar.
>
No, because replacement of macro by it's value is essentially
search-and-replace, while evaluation of arithmetics expressions is
essentially code interpretation.
--
Andrew W. Nosenko <address@hidden>
- Re: Arithmetic Shift, (continued)
- Re: Arithmetic Shift, Andrew W. Nosenko, 2010/12/10
- Re: Arithmetic Shift, Paul Eggert, 2010/12/10
- Re: Arithmetic Shift, Peter Breitenlohner, 2010/12/10
- Re: Arithmetic Shift, Andrew W. Nosenko, 2010/12/10
- Re: Arithmetic Shift, Bob Friesenhahn, 2010/12/10
- Re: Arithmetic Shift, Andrew W. Nosenko, 2010/12/11
Re: Arithmetic Shift, Ben Pfaff, 2010/12/10
Re: Arithmetic Shift, Paul Eggert, 2010/12/10
Re: Arithmetic Shift,
Andrew W. Nosenko <=
Re: Arithmetic Shift, Paul Eggert, 2010/12/11
Re: Arithmetic Shift, Andrew W. Nosenko, 2010/12/11
Re: Arithmetic Shift, Andrew W. Nosenko, 2010/12/11