unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: David Kastrup <dak@gnu.org>
Cc: emacs-devel@gnu.org
Subject: Re: Preventing warnings in FIXNUM_OVERFLOW_P
Date: Thu, 18 Jan 2007 19:34:24 +0100	[thread overview]
Message-ID: <85lkk0npzj.fsf@lola.goethe.zz> (raw)
In-Reply-To: <E1H7b3N-0006PV-2q@fencepost.gnu.org> (Richard Stallman's message of "Thu\, 18 Jan 2007 12\:27\:57 -0500")

Richard Stallman <rms@gnu.org> writes:

> Ian Lance Taylor <iant@google.com> 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	other threads:[~2007-01-18 18:34 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-01-18 17:27 Preventing warnings in FIXNUM_OVERFLOW_P Richard Stallman
2007-01-18 18:34 ` David Kastrup [this message]
2007-01-18 19:39   ` Stefan Monnier
2007-01-19 10:42     ` Richard Stallman
2007-01-19 11:50       ` Eli Zaretskii
2007-01-19 19:19         ` Stefan Monnier
2007-01-20  2:10           ` Richard Stallman
2007-01-20 13:45             ` Eli Zaretskii
2007-01-21  6:49               ` Richard Stallman
2007-01-19 10:42   ` Richard Stallman
2007-01-18 21:49 ` Eli Zaretskii
2007-01-19 10:43   ` Richard Stallman
2007-01-19 10:57     ` Eli Zaretskii
2007-01-20  2:10       ` Richard Stallman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=85lkk0npzj.fsf@lola.goethe.zz \
    --to=dak@gnu.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).