G
glen herrmannsfeldt
You could sort an array of pointers, and use binary search to
find a pointer in that array.
For the question "does the pointer p point into the array q which
has a size of n bytes", it would be sufficient if the difference
between unrelated pointers did yield an unspecified (but not
undefined) result. Take the difference n, check that it is
between 0 and the size of the array, then compare p
and &array [n].
And C allows for machines that don't have a pointer compare operation.
If you really need one, put your pointers into a struct, add
another field that would be the distance from the beginning of memory
if all allocated regions were allocated sequentially. You might even
add in a little padding between them. Using those, then, you can
do any comparisons that you might otherwise do using the appropriate
pointers.
(As previously noted JVM has no operation other than equality and
non-equality on object references. There might be others, too.
Protected-mode x86 in large model normally compares only the offset.
In huge model, it should compare both selector and offset.
-- glen