unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Paul Eggert <eggert@cs.ucla.edu>
Cc: 13419@debbugs.gnu.org
Subject: bug#13419: make 'eabs' act more like a function
Date: Sat, 12 Jan 2013 08:25:06 -0500	[thread overview]
Message-ID: <jwvk3riy1qw.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <50F10643.8000408@cs.ucla.edu> (Paul Eggert's message of "Fri, 11 Jan 2013 22:44:19 -0800")

> This patch doesn't fix any bugs, it's just a code cleanup.

[...]

> -/* We used to use `abs', but that clashes with system headers on some
> -   platforms, and using a name reserved by Standard C is a bad idea
> -   anyway.  */
> -#if !defined (eabs)
> -#define eabs(x)         ((x) < 0 ? -(x) : (x))
> +/* Return the absolute value of X, without evaluating X more than once.
> +   X should be a signed integer, and X's absolute value should not
> +   exceed the maximum for its promoted type.
> +
> +   If _Generic or typeof works, speed things up a bit by avoiding the
> +   conversion to intmax_t.  The "~" promotes X's type, and checks that
> +   X is an integer.  */
> +#if HAVE_C__GENERIC
> +# define eabs(x) \
> +    (_Generic (~ (x), int: abs, long: labs, long long: llabs, default: imaxabs) \
> +     (x))
> +#elif HAVE_TYPEOF
> +# define eabs(x) ({ typeof (~ (x)) eabsx = x; eabsx < 0 ? -eabsx : eabsx; })
> +#else
> +# define eabs(x) imaxabs (x)
>  #endif
 
Huh?  Do you really consider this code cleaner?  It's hideous and
impenetrable.  Not cool!


        Stefan





  parent reply	other threads:[~2013-01-12 13:25 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-12  6:44 bug#13419: make 'eabs' act more like a function Paul Eggert
2013-01-12  9:11 ` Eli Zaretskii
2013-01-12 13:25 ` Stefan Monnier [this message]
2013-01-12 23:06   ` Paul Eggert
2013-01-13  0:26     ` Stefan Monnier
2013-01-13  1:41       ` Paul Eggert
2013-01-19 22:36         ` Paul Eggert

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=jwvk3riy1qw.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=13419@debbugs.gnu.org \
    --cc=eggert@cs.ucla.edu \
    /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).