Advertisement
Guest User

Untitled

a guest
Feb 13th, 2016
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. // Consider a "relative" pointer to some offset within
  2. // a buffer with some base address.
  3.  
  4. struct RelativePtr {
  5. void* base;
  6. int offset;
  7. }
  8.  
  9. // Now consider some operation to compute the relative address:
  10.  
  11. void* absolute(RelativePtr p) {
  12. return p.base + p.offset;
  13. }
  14.  
  15. // Is there any language out there that would let me
  16. // abstract over when and where the value of `base` is known?
  17.  
  18. // For example, let's say you have a structure with
  19. // two relative pointers with the same offset:
  20.  
  21. struct Foo {
  22. RelativePtr a;
  23. RelativePtr b;
  24. }
  25.  
  26. // Ideally, the runtime representation of Foo would be:
  27.  
  28. struct Foo {
  29. void* base;
  30. int offsetA;
  31. int offsetB;
  32. }
  33.  
  34. // And the absolute function should still work:
  35.  
  36. Foo foo = ...;
  37. void* p = absolute(foo.a);
  38.  
  39. // There needs to be some way to express the shared-base pointer
  40. // constraint, but no language that I know of offers this.
  41.  
  42. // Does this exist somewhere? Is there relavant literature?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement