News for hackers. Stuff that matters.
Re:You Can't Always Hash Pointers in C by userbinator on Tuesday May 31, 2016 @07:05AM (#11805837)
but it must have been something totally mad and not reasonably castable to int or even int.*

As long as you can impose an ordering on the elements in memory and thus derive a number for each one, it's possible to define the straightforward representation of a pointer. 4 chars per word is an easy case since you can just let char* be a number with the lowest 2 bits indicating the index within a single word, and the rest of the bits are the word-address. int* can be the same number with the lowest 2 bits always 0. If word addresses are smaller than 36 bits, then values with the higher bits set are invalid, and if they're larger, then use multiple words to hold them.

Working with chars on such a machine is going to involve a lot of shifting and otherwise data movement, but there you go, a way to implement C pointers on such a machine.

Re:You Can't Always Hash Pointers in C by qb45 on Tuesday May 31, 2016 @07:33AM (#11805922)
> int* can be the same number with the lowest 2 bits always 0.

And now you have to right-shift int pointers on every dereference for some dubious benefit. It's easier and more efficient to make pointer arithmetic and casting painful.

Re:You Can't Always Hash Pointers in C by adrianratnapala on Friday June 03, 2016 @05:52PM (#11833550)
No, you left-shift them on every cast.

And is someone type-puns using a union, they get a thing four times samller than they might have expected. Stil it is totally well behaved in a hash.