|
|
|
|
|
by mananaysiempre
482 days ago
|
|
I meant integers in general, not ints specifically. That is to say, the standard does not guarantee that, if p and q are (say) void pointers and p == q, then (uintptr_t)p == (uintptr_t)q. (Neither does it guarantee that, if p == NULL, then (uintptr_t)p == 0, but I digress.) Mere size shenanigans are not enough for things to get that bad. What you need is for there to be multiple ways to represent a pointer to the same place in memory, like on real-mode x86 in the large memory model. The practical result is, you need to write XOR-linked-list operations something like this: struct node { uintptr_t link; };
void prepend(uintptr_t head, struct node *n) {
struct node *h = (void *)head;
uintptr_t node = (uintptr_t)(void *)n;
n->link = head ^ h->link;
((struct node *)(void *)h->link)->link ^= head ^ node;
h->link = node;
}
and you cannot for example make head, the sentinel node pointer, into a struct entry * instead, it has to be exposed as an uintptr_t (a canonical integer representation of that pointer). |
|