Why is size_t unsigned?
Ali Çehreli
acehreli at yahoo.com
Sun Jul 21 20:58:30 PDT 2013
On 07/21/2013 08:47 PM, JS wrote:
> Doing simple stuff like
>
> for(int i = 0; i < s.length - 1; i++) fails catastrophically if s is
> empty. To make right one has to reduce performance by writing extra
checks.
Checks are needed for program correctness. If not in source code, in
compiler generated code, or the microprocessor itself. The compiler and
the microprocessor would not do such things for performance reasons. It
is because sometimes only the programmer knows that the check is
unnecessary.
> There seems to be no real good reason why size_t is unsigned...
How about, every addressable memory locations must be countable?
> Surely one doesn't require too many strings larger than 2^63 bits on
an x64
> os...
Agreed.
> I running into a lot of trouble because of the way D deals with implicit
> casting of between signed and unsigned.
D is behaving the same way as C and C++ there.
> please don't tell me to use foreach... isn't not a panacea.
I would still prefer foreach because it is more convenient and safer
because of needing less code.
Ali
More information about the Digitalmars-d-learn
mailing list