• bleistift2@sopuli.xyz
    link
    fedilink
    English
    arrow-up
    0
    ·
    12 days ago

    linked lists, trees, objects with references to other objects

    That’s not a pointer to another pointer, but a pointer to a data structure that happens to contain another pointer.

    • Lightfire228@pawb.social
      link
      fedilink
      arrow-up
      0
      ·
      edit-2
      12 days ago

      The distinction is meaningless in the land of Opcode’s and memory addresses

      For example, a struct is just an imaginary “overlay” on top of a contiguous section of memory

      Say you have a struct

      struct Thing {
        int a;
        int b;
        Thing* child;
      }
      
      Thing foo {}
      

      You could easily get a reference to foo->child->b by doing pointer arithmetic

      *((*((*foo) + size(int)*2)) +size(int))
      

      (I’ve not used C much so I’ve probably got the syntax wrong)

      • bleistift2@sopuli.xyz
        link
        fedilink
        English
        arrow-up
        0
        ·
        11 days ago

        Yes, you can do crazy shit if you try hard enough, but every reasonable programmer would access foo->child->b als foo->child->b and not via that crazy LISPy expression.

        By question was: Why would you have a pointer to a memory address that itself only holds a pointer somewhere else?

        So far the only reasonable explanation is from @Victoria@lemmy.blahaj.zone:

        • arrays of function pointers
        • pass by reference of a pointer