[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: source(builtin) and read(2)
From: |
Paul Eggert |
Subject: |
Re: source(builtin) and read(2) |
Date: |
Sat, 31 Mar 2007 07:42:43 -0700 |
User-agent: |
Gnus/5.1008 (Gnus v5.10.8) Emacs/21.4 (gnu/linux) |
Geoff Clare <address@hidden> writes:
> Paul Eggert <address@hidden> wrote, on 30 Mar 2007:
>>
>> So I don't see the point of insisting on a guarantee that SSIZE_MAX
>> must be the maximum representable ssize_t value. What can a portable
>> application do with that guarantee that it couldn't do otherwise?
>
> It can use SSIZE_MAX for the same kind of things as INT_MAX et al. are
> used, e.g. to check that an arithmetic operation will not overflow
> before performing it.
That is true regardless of whether SSIZE_MAX is the maximum
representable ssize_t value. For example, this code:
bool sum_would_overflow (ssize_t a, ssize_t b)
{
return a < 0 ? b < 0 : SSIZE_MAX - a < b;
}
works either way. (Not that I expect most programs are this careful!)
Portable code cannot attempt to create an ssize_t value greater than
SSIZE_MAX (as this leads to undefined behavior), so -- if we're
concerned only about portable code -- it doesn't matter whether size_t
values greater than SSIZE_MAX exist in the underyling implementation.
- Re: source(builtin) and read(2), (continued)
Re: source(builtin) and read(2), Paul Eggert, 2007/03/30