logoalt Hacker News

frmdstryrtoday at 7:46 PM3 repliesview on HN

Do any languages have a notion of "relative pointers"? So in the example if instead of appending "line" as ptr & len, it'd instead be appending an offset & len which could in theory be used to safely compute the actual location even with relocations.


Replies

afdbcreidtoday at 10:40 PM

That is called an index. If you want it to be standalone, you can bundle it with the ArrayList.

show 2 replies
amlutotoday at 9:17 PM

Languages with dependent types can express things like “this offset is in bounds relative to this other array”, which is maybe what you’re thinking of.

Someonetoday at 8:19 PM

If you squeeze your eyes a bit, C compilers for Windows used to have them, with far pointers (https://en.wikipedia.org/wiki/Far_pointer)

Similarly, CPU architectures that use descriptors can (have to?) have languages with that notion.

show 2 replies