Richard Stallman <[EMAIL PROTECTED]> writes:

> In Emacs we have a macro that tends to produce the warning
> 
>    comparison is always false due to limited range of data type
> 
> when compiling for 64-bit machines.  EMACS_INT is 64 bits
> in that case.  Here is the macro:
> 
> #define FIXNUM_OVERFLOW_P(i) \
>   ((EMACS_INT)(i) > MOST_POSITIVE_FIXNUM \
>    || (EMACS_INT) (i) < MOST_NEGATIVE_FIXNUM)
> 
> When this macro is used on an expression that has type int, it
> produces those warnings, and there is no way to change the macro to
> prevent the warnings.  We used the workaround of copying the
> expression into an EMACS_INT in a previous statement, but that is
> cumbersome and ugly.

gcc has issued this warning for quite a while.  It has been around at
least since this change:

Sun Apr 17 01:21:35 1988  Richard Stallman  (rms at frosted-flakes.ai.mit.edu)

        * typecheck.c (shorten_compare): Warn about constant result only in
        cases like (char)x < 0x80, where old C compilers made it -0x80.

I'm not sure whether anything has changed in this area to cause the
warnings to appear more frequently today.


> Is there a way to write the macro so as to suppress this warning?

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)

Ian

Reply via email to