[Top][All Lists]

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

Re: [Emacs-diffs] trunk r114450: * dispnew.c (clear_glyph_row, copy_row_

From: Paul Eggert
Subject: Re: [Emacs-diffs] trunk r114450: * dispnew.c (clear_glyph_row, copy_row_except_pointers):
Date: Tue, 24 Sep 2013 08:26:24 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.0

Daniel Colascione wrote:
> Signed integers have undefined overflow behavior and sometimes
> result in less efficient code. If anything, we should prefer unsigned
> integer types.

The general Emacs style is to prefer signed integers to unsigned.
That's why the Emacs source code prefers ptrdiff_t to size_t, for
example.  This is not a style that I originally favored, but I've
learned to like its advantages.  Most importantly, it leads to
more-understandable code, since signed arithmetic is closer to how
people normally understand numbers: it's counterintutive that a
large positive number X can satisfy the predicate (X < -1), which
can happen with unsigned arithmetic.  And as a side effect, signed
arithmetic often leads to more-efficient code, since the compiler
can take advantage of the fact that behavior is undefined on

There are a few exceptions to the general style; one is bitmasks
(where the integers are not really numbers, but are bit strings).
Another is char, where unsigned char is often used, as it's
simpler (and typically, this doesn't have the problem with -1
anyway).  Still another are hash values and a few other places
where the performance advantage of unsigned arithmetic is
compelling.  But generally, we prefer signed integers.

reply via email to

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