Is this a bug?

Is it possible to store different generic types? via Digitalmars-d digitalmars-d at puremagic.com
Sat Dec 10 00:09:00 PST 2016


I'm pretty sure the following code should work, but it doesn't.

```
bool intersect(ptrdiff_t targetX, ptrdiff_t targetY, size_t 
targetWidth, size_t targetHeight, ptrdiff_t x, ptrdiff_t y, 
size_t width, size_t height)
{
  return targetX < x + width &&
        x < targetX + targetWidth &&
        targetY < y + height &&
        y < targetY + targetHeight;
}

void main() {
	import std.stdio;
	writeln(intersect(0,0,800,600,     0,150,148,148));
	writeln(intersect(0,0,800,600,     -10,150,148,148));
}
```

It outputs:
```
true
false
```

On the contrary if you write the same piece of code in other 
languages ex. C#

(Ran it through Linqpad)
```
bool intersect(int targetX, int targetY, uint targetWidth, uint 
targetHeight, int x, int y, uint width, uint height)
{
  return targetX < x + width &&
        x < targetX + targetWidth &&
        targetY < y + height &&
        y < targetY + targetHeight;
}

void Main() {
	intersect(0,0,800,600,     0,150,148,148).Dump();
	intersect(0,0,800,600,     -10,150,148,148).Dump();
}
```

Then it outputs:
```
true
true
```

Is it a bug or is it intended behavior?




More information about the Digitalmars-d mailing list