Re:A critique of "How to C in 2016"
by zodiac on Friday January 15, 2016 @06:54AM
(#10908687)
I think comparing (using <) pointers to unrelated objects is undefined behavior. So you do not get a consistent ordering.
[ Parent
| on HN ]
The 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.