autoconf
[Top][All Lists]
Advanced

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

Re: Arithmetic Shift


From: Mike Gibson
Subject: Re: Arithmetic Shift
Date: Thu, 9 Dec 2010 09:35:56 -0700

On Thu, Dec 9, 2010 at 9:26 AM, Philip Herron <address@hidden> wrote:
> On 8 December 2010 04:41, Mike Gibson <address@hidden> wrote:
>> Does a test already exist that checks for if the >> operator in C does
>> arithmetic shift?  Section 5.5.1 "Portability of C Functions" of the
>> manual mentions the problem, but lists nothing about a way of
>> determining actual behavior.  Seems that it would simple enough that I
>> thought I would ask before I dive in and write something myself.
>
> You can write your own tests within your configure.ac, but to be fair
> operators like that for me i would _expect_ them to be there in any c
> compiler since its such a basic and important operation.

The problem isn't the existence of the operator.  The problem is that
if you want to do an arithmetic shift, then you can't trust that >>
with signed values will always do the trick.  The following test in
configure.ac does this:

dnl **** Check for arithmetic right shifting ****
AC_CACHE_CHECK([whether the right shift operator is an arithmetic right shift],
        wine_cv_arithmetic_right_shift,
        AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
[[#if ((-4 >> 1) != -2)
#error "No simple arithmetic right shift"
#endif]], [[]])],
        [wine_cv_arithmetic_right_shift=yes],
        [wine_cv_arithmetic_right_shift=no]))
if test "$wine_cv_arithmetic_right_shift" = "yes"
then
  AC_DEFINE(HAVE_SIMPLE_ARITHMETIC_RIGHT_SHIFT,1,[Define if the right
shift operator is an arithmetic shift])
fi

Mike Gibson



reply via email to

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