Op Tue, 19 Jan 2010, schreef Graeme Geldenhuys:
Show quoted text 6 lines
Michael Van Canneyt wrote:
>
> Why should it be better ? It doesn't really matter anyway.
PtrUInt has a larger range than PtrInt (allowing full access to memory
address range). Plus, I don't think pointers can be negative values.
The problem occurs when doing pointer arithmetic "ptrint+integer" is a bug, because it will overflow if the original pointer<$8000000 and the result pointer>=$8000000. It is especially dangerous in loops like:
q:=p+distance;
while p<q do
begin
{...}
inc(p);
end;
I don't want to think how many bugs have been coded this way :)
However, when using pointers as handles it is another matter... Handles are not to be used in any calculation, so they cannot overflow. Who cares if you get a negative handle?
Daniël