On Tue, 16 Jun 2020, Feng Xue OS wrote:

Here is an question about pointer operation:
Pointer is treated as unsigned in comparison operation, while distance between
pointers is signed. Then we can not assume the below conclusion is true?

(ptr_a > ptr_b)     =>     (ptr_a - ptr_b) >= 0

Yes you can. It is illegal to use either expression if ptr_a and ptr_b do not point inside the same object, and objects are not allowed to be larger than half the address space.

Comparing arbitrary pointers (not in the same object) is done with (uintptr_t)ptr_a > (uintptr_t)ptr_b.

--
Marc Glisse

Reply via email to