'int' is enough for 'length' to migrate code from x86 to x64
Don via Digitalmars-d
digitalmars-d at puremagic.com
Wed Nov 19 05:47:50 PST 2014
On Tuesday, 18 November 2014 at 18:03:35 UTC, ketmar via
Digitalmars-d wrote:
> On Tue, 18 Nov 2014 17:59:04 +0000
> David Eagen via Digitalmars-d <digitalmars-d at puremagic.com>
> wrote:
>
>> Isn't the purpose of size_t is to be large enough to address
>> all available memory? A negative value is not only too small
>> but doesn't make sense when discussing lengths.
>>
>> Correctness requires using size_t.
> yes. besides, there is no such thing as "negative length", so
> it's
> somewhat... weird to use signed integer for length.
A length can certainly be negative. Just as a bank balance can be
negative. It's just a number.
If I have two pencils of length 10 cm and 15 cm, then the first
one is -5 cm longer than the other.
Of course any physical pencil is always of positive length, but
that doesn't mean that typeof(pencil.length) can never be
negative.
More information about the Digitalmars-d
mailing list