Which type it better to use for array's indices?

Chris Wright via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Dec 4 07:54:05 PST 2015


On Fri, 04 Dec 2015 13:24:16 +0000, ref2401 wrote:

> It seem like `size_t` suites well because 'is large enough to represent
> an offset into all addressible memory.'
> (http://dlang.org/spec/type.html#size_t)
> However sometimes I want index to be less the 0 to represent a
> particular case.

ptrdiff_t is the signed equivalent of size_t. You could use that -- 
unless you anticipate having an array longer than two billion elements 
and are compiling to a 32-bit program.


More information about the Digitalmars-d-learn mailing list