Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

For purposes of future language design: why not just ban conversion from integers to pointers? Pointers have metadata that integers can't provide, therefore the conversion is impossible, QED. What's the use case for it outside of, say, binary executable loaders?


> What's the use case for it outside of, say, binary executable loaders?

If you're doing low-level optimizations, and you know that your pointed-to objects are, say, 8-byte-aligned, then you can use the lower 3 bits of your pointer for storing metadata. In certain cases, that can be immensely useful. Some GC implementations use this trick, for example.


One could imagine a specific primitive operation in the language that lets you adjust the low bits of a pointer without casting it to an integer and back.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: