Signed-unsigned comparisons in Phobos

Walter Bright newshound2 at digitalmars.com
Fri Aug 12 15:08:28 PDT 2011


On 8/12/2011 11:32 AM, Jacob Carlborg wrote:
> On 2011-08-12 20:16, Walter Bright wrote:
>> On 8/12/2011 8:52 AM, Jonathan M Davis wrote:
>>> it's a practice that many
>>> people don't seem to follow (in both C/C++ and D), since it's so
>>> natural to
>>> use int (or auto in D),
>>
>> Back in the olden days of C, it was "best practice" to use int as an
>> index. Times have changed, but old habits die hard.
>
> Just out of curiosity, why was that?
>

1. size_t didn't exist

2. sizeof(int) == sizeof(pointer) pretty much everywhere

3. Signed indices meant you could index backwards

4. K+R used 'int' as an index everywhere


More information about the Digitalmars-d mailing list