be something like this:
pure void * memset(return void * s, int c, size_t n)
{
foreach (i; 0 .. n)
(cast(char *) s)[i] = cast(char) c;
return s;
}
What is the return doing there?
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
In Patterns of Human Error, the slide 31 point that you should replce int with
size_t
why that consider an error ?
%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
void main()
{
size_t val = int.max+1;
int val2 = val;
writeln(val2);
}
writes -2147483648
That should give you a hint.
size_t val1 = int.max+1;
int val2 = int.max+1;
writeln(val1); // 2147483648
writeln(val2); // -2147483648
very clear example
thanks you both
definitions in object_.d:
version(X86_64)
{
alias ulong size_t;
alias long ptrdiff_t;
alias long sizediff_t;
}
else
{
alias uint size_t;
alias int ptrdiff_t;
alias int sizediff_t;
}
And an example:
void main()
{
size_t val = size_t.max;// maximum unsigned 32bit
Edit: I just saw you've already figured this out. :)