This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Preventing warnings


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.

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

If not, I think one ought to be implemented.  I have a suggestion for
what it could look like:

#define FIXNUM_OVERFLOW_P(i) \
  ((EMACS_INT)(int)(i) > MOST_POSITIVE_FIXNUM \
   || (EMACS_INT)(int)(i) < MOST_NEGATIVE_FIXNUM)

The casts to int could be interpreted as meaning "yes I know this is
limited to the range of of ints, so don't warn me about the
consequences of that fact."

Please respond.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]