emacs-devel
[Top][All Lists]
Advanced

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

Re: ptrdiff_t misuse


From: Paul Eggert
Subject: Re: ptrdiff_t misuse
Date: Fri, 06 Jul 2012 10:39:15 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120605 Thunderbird/13.0

On 07/06/2012 09:42 AM, Dmitry Antipov wrote:
> I read ptrdiff_t exactly as "difference between pointers", and this is
> the minor drawback; the major one is that there is no standard unsigned
> counterpart, like for size_t/ssize_t pair.

For buffer positions and the like, Emacs code can take size_t to be
the unsigned counterpart of ptrdiff_t.  For Emacs we typically prefer
signed integers, so the need for size_t is rare -- in fact some of the
current uses of size_t should be changed to ptrdiff_t, for consistency
with the usual Emacs style.

There are hosts with size_t wider than ssize_t (POSIX allows this).
That is why we use ptrdiff_t, not ssize_t, for buffer positions and
the like -- on those hosts, ssize_t wouldn't work for large buffers.
Conversely, on some (rare) hosts ptrdiff_t is wider than size_t (POSIX
allows this too).  As far as I know Emacs has never been ported to
these hosts but it should work, since buffer positions will fit into
ptrdiff_t.



reply via email to

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