Re: int or size_t ?

2011-05-08 Thread Stewart Gordon
On 07/05/2011 18:09, %u wrote: In Patterns of Human Error, the slide 31 point that you should replce int with size_t why that consider an error ? For those who aren't sure what this is on about: http://www.slideshare.net/dcacm/patterns-of-human-error But the short answer is because dim is a si

Re: int or size_t ?

2011-05-07 Thread Andrej Mitrovic
Edit: I just saw you've already figured this out. :)

Re: int or size_t ?

2011-05-07 Thread Andrej Mitrovic
Actually my example was bad. What I wanted to say is that size_t will be 64bit on 64bit platforms while int will stay 32bit. Another difference is that size_t is unsigned. So it's bad to use int even if you're sure you're only going to compile only on 32bit platforms. Here's the relevant definitio

Re: int or size_t ?

2011-05-07 Thread %u
size_t val1 = int.max+1; int val2 = int.max+1; writeln(val1); // 2147483648 writeln(val2); // -2147483648 very clear example thanks you both

Re: int or size_t ?

2011-05-07 Thread Andrej Mitrovic
void main() { size_t val = int.max+1; int val2 = val; writeln(val2); } writes -2147483648 That should give you a hint.

Re: int or size_t ?

2011-05-07 Thread bearophile
%u: > In Patterns of Human Error, the slide 31 point that you should replce int with > size_t > why that consider an error ? If T is a byte and the array size is 5 billion items, on 64 bit systems...? In the little find() function you compare it with the length, that's a size_t. Someone else wi

int or size_t ?

2011-05-07 Thread %u
In Patterns of Human Error, the slide 31 point that you should replce int with size_t why that consider an error ?