News for hackers. Stuff that matters.
Re:You Can't Always Hash Pointers in C (2016) by saagarjha on Wednesday September 19, 2018 @01:57AM (#18022042)
I don’t see anything wrong with using pointers as keys in a lookup table. There’s nothing non-reproducible about this.
Re:You Can't Always Hash Pointers in C (2016) by maljx on Wednesday September 19, 2018 @04:22AM (#18022706)
Compiler/runtime can create two pointers with different integer values that point to same memory address. The article explains a few reasons why that might happen. It's very uncommon, but it's valid in the standard.
Re:You Can't Always Hash Pointers in C (2016) by delhanty on Wednesday September 19, 2018 @02:10AM (#18022093)
>There’s nothing non-reproducible about this.

No that's false. See my clarification above.

Re:You Can't Always Hash Pointers in C (2016) by saagarjha on Wednesday September 19, 2018 @03:11AM (#18022362)
I really don't care what the actual value of the pointers are, since I'm not going to use them for anything other than key lookup. The thing that breaks in your case is hash table iteration, but if I'm not doing that I still don't see any non-reproducible behavior other than slight timing differences.
Re:You Can't Always Hash Pointers in C (2016) by Zanni on Wednesday September 19, 2018 @05:11AM (#18022902)
If you read the article, there's an explicit mention of the possibility of tagged pointers for some implementations, where the low-order bits represent the address and the high-order bits are used for housekeeping and might change dynamically. Thus the pointer to the same object might naively cast to different integers at different times in program execution. That will lead to non-reproducible behavior.
Re:You Can't Always Hash Pointers in C (2016) by wruza on Wednesday September 19, 2018 @08:34AM (#18023703)
Given the factual amount of times it will happen, even this small thread is not worth it except for few pedants. And on architectures where it will, and on compilers that dare to make it happen — it will break much more than just your clever code anyway. All these ancient standard details are there only for history. In reality, you cannot even change the direction of memcpy(3) without turning the world upside down.
Re:You Can't Always Hash Pointers in C (2016) by rurban on Wednesday September 19, 2018 @06:56PM (#18028306)
sure, but in practice everybody knows the actually used bits of every pointers per platform. on amd64 e.g. it's the 2 lowest and 16 highest which need to be masked off for comparison. it's simply platform and vm dependent.

I know very well where and how I'm able to compare ptrs in a hash table, and I'm doing it all the time. just complaining out loud is no solution.

Re:You Can't Always Hash Pointers in C (2016) by xamuel on Wednesday September 19, 2018 @02:48AM (#18022262)
There's nothing non-reproducible about it within a particular run. Of course it would be silly to write a pointer hash table to disk!