Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Consider a "relative" pointer to some offset within
- // a buffer with some base address.
- struct RelativePtr {
- void* base;
- int offset;
- }
- // Now consider some operation to compute the relative address:
- void* absolute(RelativePtr p) {
- return p.base + p.offset;
- }
- // Is there any language out there that would let me
- // abstract over when and where the value of `base` is known?
- // For example, let's say you have a structure with
- // two relative pointers with the same offset:
- struct Foo {
- RelativePtr a;
- RelativePtr b;
- }
- // Ideally, the runtime representation of Foo would be:
- struct Foo {
- void* base;
- int offsetA;
- int offsetB;
- }
- // And the absolute function should still work:
- Foo foo = ...;
- void* p = absolute(foo.a);
- // There needs to be some way to express the shared-base pointer
- // constraint, but no language that I know of offers this.
- // Does this exist somewhere? Is there relavant literature?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement