[Top][All Lists]

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

Re: Preventing warnings in FIXNUM_OVERFLOW_P

From: David Kastrup
Subject: Re: Preventing warnings in FIXNUM_OVERFLOW_P
Date: Thu, 18 Jan 2007 19:34:24 +0100
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.92 (gnu/linux)

Richard Stallman <address@hidden> writes:

> Ian Lance Taylor <address@hidden> wrote:
>     You can avoid it by using unsigned types.  I think that something like
>     this will do the trick:
>     #define FIXNUM_OVERFLOW_P(i)                                      \
>       ((unsigned long long)(i) > MOST_POSITIVE_FIXNUM         \
>        && (unsigned long long)(i) < MOST_NEGATIVE_FIXNUM)
> Would someone please give that approach a try and see if it works?  I
> am having too much trouble with concentration right now to see whether
> that code is correct -- it might need somewhat more change than that
> in order to get the comparisons right in an unsigned type.

unsigned long long is neither guaranteed to exist on all supported
architectures, nor guaranteed to be longer than long.

It seems to me like something along the lines of

#define FIXNUM_OVERFLOW_P(i) \
  (((unsigned long)(i)-(unsigned long)MOST_NEGATIVE_FIXNUM) > \
    (unsigned long)MOST_POSITIVE_FIXNUM)

should do the trick.  A few more casts than strictly necessary, but in
that manner there is a chance that the compiler will not complain.  I
am assuming here that the natural type of i is (long int), if it isn't
adapt the casts accordingly.

David Kastrup, Kriemhildstr. 15, 44793 Bochum

reply via email to

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