337
you are viewing a single comment's thread
view the rest of the comments
[-] Lightfire228@pawb.social 16 points 6 days ago* (last edited 5 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 1 points 5 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
[-] Lightfire228@pawb.social 1 points 4 days ago

I'm more talking about theory than practical.

I've not developed anything in C/C++, so I don't know practical uses for a double pointer, aside from multidimensional arrays, or arrays of pointers

My point was that, conceptually, pointers to pointers is how most complex data structures work. Even if the C representation of said code doesn't have a int** somewhere

[-] bane_killgrind@slrpnk.net 1 points 5 days ago

Magic.

Blasphemy.

this post was submitted on 29 Dec 2024
337 points (98.8% liked)

Programmer Humor

19817 readers
176 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS