[Top][All Lists]

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

Re: source(builtin) and read(2)

From: Clive D.W. Feather
Subject: Re: source(builtin) and read(2)
Date: Mon, 26 Mar 2007 08:39:43 +0100
User-agent: Mutt/1.5.3i

Schwarz, Konrad said:
> While we're at it, I would be interested in the rational for "inventing"
> ssize_t and not using ptrdiff_t instead, if anyone would care to
> comment.

size_t has to be able to hold the size of the largest object. It is an
unsigned type.

ptrdiff_t has to be able to hold the largest difference between two
pointers; it is a signed type.

The two need not be a signed/unsigned pair. For example, if a system has a
maximum object size of 64,000 bytes, then size_t needs to be at least 16
bits but ptrdiff_t needs to be at least 17 bits. Thus it would be
legitimate for size_t to be (16 bit) unsigned short but ptrdiff_t to be
(32 bit) signed int.

ssize_t is the signed type corresponding to size_t. In the above example,
it is required to be signed short. It's possible for a legitimate
subtraction of two pointers to generate a value that can't fit in ssize_t.
However, because size_t and ssize_t are a signed/unsigned pair, they have
useful properties (for example, when dealing with varargs lists).

Clive D.W. Feather  | Work:  <address@hidden>   | Tel:    +44 20 8495 6138
Internet Expert     | Home:  <address@hidden>  | Fax:    +44 870 051 9937
Demon Internet      | WWW: http://www.davros.org | Mobile: +44 7973 377646
THUS plc            |                            |

reply via email to

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