3 ms·
I think comparing (using <) pointers to unrelated objects is undefined behavior. So you do not get a consistent ordering.
by zodiac 11y ago
I think comparing (using <) pointers to unrelated objects is undefined behavior. So you do not get a consistent ordering.
- cesarb 11y agoThe part I quoted is talking about casting the pointers to uintptr_t (which is defined behavior) and comparing the resulting uintptr_t (since it's an integer, comparing it is defined behavior). It's not talking about comparing the pointers directly (which is undefined behavior). His argument is that, while defined behavior, "(uintptr_t)ptr_a < (uintptr_t)ptr_b" is useless; I disagree, since it's a well-known trick to prevent AB/BA type deadlocks.