This allows to write very short comparison function when we are
comparing just pointer values:
return ((intptr_t)((uintptr_t)a->ptr - (uintptr_t)b->ptr));
Differential D35722
tree(3): allow the compare function to return any signed type glebius on Jul 6 2022, 9:20 AM. Authored by Tags None Referenced Files
Subscribers
Details This allows to write very short comparison function when we are return ((intptr_t)((uintptr_t)a->ptr - (uintptr_t)b->ptr));
Diff Detail
Event TimelineComment Actions AFAIK, it is not part of standard, yet. The point is that tree.h already requires it for RB_PARENT :) Comment Actions Point taken on __typeof. In your example of use return ((intptr_t)((uintptr_t)a->ptr - (uintptr_t)b->ptr)); can overflow, but (assuming that ptr points to something bigger than char) return ((intptr_t)((uintptr_t)a->ptr/2 - (uintptr_t)b->ptr/2)); does not. Otherwise, it's okay by me. |