Off-topic: C pointer semantics

David Hopwood david.nospam.hopwood@REDACTED
Tue Dec 13 15:19:42 CET 2005


Marthin Laubscher wrote:
> (**) on Mikael's (*): Careful now. Yes, it true, ptr1 - ptr2 is a signed
> int, but it might not have the value you'd expect. There's a pretty good
> reason the pointers must be to the same type - that's because value of ptr1
> - ptr2 is supposed to be the offset (in memory) between the two objects
> being pointed at. Unless theyre byte pointers (char* etc), the value of ptr1
> - ptr2 is not returned in bytes, but in "element size units".

Right, but they were both 'char *' in this case. And even if they were of
different types, '(long) ptr1 - (long) ptr2' is still almost certainly not
what you want: in that case you _may_ want '(char *) ptr1 - (char *) ptr2'.

(Sorry about the off-topic discussion.)

-- 
David Hopwood <david.nospam.hopwood@REDACTED>




More information about the erlang-questions mailing list