▲ 350 ▼ I love new features (lemmy.zip) submitted 2 years ago by Maven@lemmy.zip to c/programmer_humor@programming.dev 43 comments fedilink hide all child comments
[+] bleistift2@sopuli.xyz -7 points 2 years ago (7 children) Why do you even have pointers to pointers? permalink fedilink source hideshow 14 child comments replies: [–] gratux@lemmy.blahaj.zone 46 points 2 years ago (1 child) many reasons, for example multidimensional arrays arrays of function pointers pass by reference of a pointer permalink fedilink source parent hideshow 2 child comments replies: [–] xmunk@sh.itjust.works 6 points 2 years ago* (1 child) In two of your cases this operator is pretty shit because at some point you'll probably want to offset the access (this isn't a knock at you but at the feature). This operator would only really be relevant to the last case which rarely comes up outside of infrastructure/library work (building a tool building tool) and usually those code bases are cautious to adopt new features too quickly anyways for portability. I've done serious C++ work (not much in the past decade though) - while references are absolutely amazing and you essentially want to pass by const ref by default I think well written maintainable C++ should maybe have a dozen heap objects tops. C++ is a better language if you generally forget that pointers and bare arrays exist. Just again - I think you're right and the fact that your list is only three things long (and arguably two of them would be misuses) is a pretty clear sign that this is an incredibly niche feature. permalink fedilink source parent hideshow 2 child comments replies: [–] sukhmel@programming.dev 17 points 2 years ago* (1 child) I don't think this operator is a real feature, tbh 😅 permalink fedilink source parent hideshow 2 child comments replies: [–] marcos@lemmy.world 6 points 2 years ago The fact that he claims it's in C++ 29, while we are in 2024 is a good hint. Or maybe he is a time traveler. Quick, go ask the next lottery numbers! permalink fedilink source parent [–] Lightfire228@pawb.social 22 points 2 years ago* (1 child) Mostly because at the lowest level of computing (machine code and CPU instructions), pointers are the only method (that I know of) of any kind of indirection. At the lowest level, there are 2 types of references: CPU registers memory addresses (pointers) Every higher level language feature for memory management (references, objects, safe pointers, garbage collection, etc) is just an abstraction over raw pointers Pointers themselves are really just abstractions over raw integers, whose sole purpose is to index into RAM With that in mind, pointers to pointers are a natural consequence of any kind of nested object hierarchy (linked lists, trees, objects with references to other objects, etc) The only other kind of indirection would be self-modifying machine code (like a Wheeler Jump). But the computing world at large has nixed that idea for a multitude of reasons permalink fedilink source parent hideshow 2 child comments replies: [+] bleistift2@sopuli.xyz -6 points 2 years ago (1 child) 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. permalink fedilink source parent hideshow 2 child comments replies: [–] Lightfire228@pawb.social 16 points 2 years ago* (last edited 2 years ago) (2 children) 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) permalink fedilink source parent hideshow 4 child comments replies: [–] bleistift2@sopuli.xyz 1 point 2 years ago (1 child) 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 permalink fedilink source parent hideshow 2 child comments replies: [–] Lightfire228@pawb.social 1 point 2 years 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 permalink fedilink source parent [–] bane_killgrind@slrpnk.net 1 point 2 years ago Magic. Blasphemy. permalink fedilink source parent [–] Gladaed@feddit.org 18 points 2 years ago* (1 child) Because stuff can own other stuff and be owned at the same time. Also, arcane jackarsery. Edit: if you want to give a function a pointer that it may change this may occur in a constructive way. I.e. replace an owned object. permalink fedilink source parent hideshow 2 child comments replies: [–] marcos@lemmy.world 5 points 2 years ago (1 child) Yeah... But it's usually a good practice to put a struct somewhere between your 30 levels of ownership. Exceptions exist, but they are not very common. Also, in C++, operators overloading may help you if you keep needing to write code like this. permalink fedilink source parent hideshow 2 child comments replies: [–] Gladaed@feddit.org 3 points 2 years ago (1 child) In C++ you should never have owning raw pointers. Unless you have a good reason™. Raw pointers are great, but not for ownership. permalink fedilink source parent hideshow 2 child comments replies: [–] qaz@lemmy.world 6 points 2 years ago* (last edited 2 years ago) (1 child) I just use unique_ptr 99% of the time permalink fedilink source parent hideshow 2 child comments replies: [–] Gladaed@feddit.org 4 points 2 years ago And you should. It even works for classes whose constructors your implementation cannot see, if you aren't a bitch about it. permalink fedilink source parent [–] BradleyUffner@lemmy.world 15 points 2 years ago Pointers just point to memory addresses, and because pointers are stored in memory addresses, it just kind of naturally falls out that way. permalink fedilink source parent [–] fibojoly@sh.itjust.works 12 points 2 years ago Pointer to pointer is fairly common stuff once you get serious with C++ but I've no idea what this abomination is supposed to even be, haha! permalink fedilink source parent [–] Klnsfw@lemmynsfw.com 5 points 2 years ago Because int main(int argc, char** argv) permalink fedilink source parent [–] mindbleach@sh.itjust.works 3 points 2 years ago (1 child) Because pointers are real. permalink fedilink source parent hideshow 2 child comments replies: [–] bleistift2@sopuli.xyz 1 point 2 years ago (1 child) That’s the best thing I’ve read in a while, and I’m only on page 2! permalink fedilink source parent hideshow 2 child comments replies: [–] mindbleach@sh.itjust.works 2 points 2 years ago (1 child) James Mickens does good work. permalink fedilink source parent hideshow 2 child comments replies: [–] bleistift2@sopuli.xyz 2 points 2 years ago If the Mossad wants your data, they’re going to use a drone to replace your cellphone with a piece of uranium that’s shaped like a cellphone That reads differently after 2024. permalink fedilink source parent
[–] gratux@lemmy.blahaj.zone 46 points 2 years ago (1 child) many reasons, for example multidimensional arrays arrays of function pointers pass by reference of a pointer permalink fedilink source parent hideshow 2 child comments replies: [–] xmunk@sh.itjust.works 6 points 2 years ago* (1 child) In two of your cases this operator is pretty shit because at some point you'll probably want to offset the access (this isn't a knock at you but at the feature). This operator would only really be relevant to the last case which rarely comes up outside of infrastructure/library work (building a tool building tool) and usually those code bases are cautious to adopt new features too quickly anyways for portability. I've done serious C++ work (not much in the past decade though) - while references are absolutely amazing and you essentially want to pass by const ref by default I think well written maintainable C++ should maybe have a dozen heap objects tops. C++ is a better language if you generally forget that pointers and bare arrays exist. Just again - I think you're right and the fact that your list is only three things long (and arguably two of them would be misuses) is a pretty clear sign that this is an incredibly niche feature. permalink fedilink source parent hideshow 2 child comments replies: [–] sukhmel@programming.dev 17 points 2 years ago* (1 child) I don't think this operator is a real feature, tbh 😅 permalink fedilink source parent hideshow 2 child comments replies: [–] marcos@lemmy.world 6 points 2 years ago The fact that he claims it's in C++ 29, while we are in 2024 is a good hint. Or maybe he is a time traveler. Quick, go ask the next lottery numbers! permalink fedilink source parent
[–] xmunk@sh.itjust.works 6 points 2 years ago* (1 child) In two of your cases this operator is pretty shit because at some point you'll probably want to offset the access (this isn't a knock at you but at the feature). This operator would only really be relevant to the last case which rarely comes up outside of infrastructure/library work (building a tool building tool) and usually those code bases are cautious to adopt new features too quickly anyways for portability. I've done serious C++ work (not much in the past decade though) - while references are absolutely amazing and you essentially want to pass by const ref by default I think well written maintainable C++ should maybe have a dozen heap objects tops. C++ is a better language if you generally forget that pointers and bare arrays exist. Just again - I think you're right and the fact that your list is only three things long (and arguably two of them would be misuses) is a pretty clear sign that this is an incredibly niche feature. permalink fedilink source parent hideshow 2 child comments replies: [–] sukhmel@programming.dev 17 points 2 years ago* (1 child) I don't think this operator is a real feature, tbh 😅 permalink fedilink source parent hideshow 2 child comments replies: [–] marcos@lemmy.world 6 points 2 years ago The fact that he claims it's in C++ 29, while we are in 2024 is a good hint. Or maybe he is a time traveler. Quick, go ask the next lottery numbers! permalink fedilink source parent
[–] sukhmel@programming.dev 17 points 2 years ago* (1 child) I don't think this operator is a real feature, tbh 😅 permalink fedilink source parent hideshow 2 child comments replies: [–] marcos@lemmy.world 6 points 2 years ago The fact that he claims it's in C++ 29, while we are in 2024 is a good hint. Or maybe he is a time traveler. Quick, go ask the next lottery numbers! permalink fedilink source parent
[–] marcos@lemmy.world 6 points 2 years ago The fact that he claims it's in C++ 29, while we are in 2024 is a good hint. Or maybe he is a time traveler. Quick, go ask the next lottery numbers! permalink fedilink source parent
[–] Lightfire228@pawb.social 22 points 2 years ago* (1 child) Mostly because at the lowest level of computing (machine code and CPU instructions), pointers are the only method (that I know of) of any kind of indirection. At the lowest level, there are 2 types of references: CPU registers memory addresses (pointers) Every higher level language feature for memory management (references, objects, safe pointers, garbage collection, etc) is just an abstraction over raw pointers Pointers themselves are really just abstractions over raw integers, whose sole purpose is to index into RAM With that in mind, pointers to pointers are a natural consequence of any kind of nested object hierarchy (linked lists, trees, objects with references to other objects, etc) The only other kind of indirection would be self-modifying machine code (like a Wheeler Jump). But the computing world at large has nixed that idea for a multitude of reasons permalink fedilink source parent hideshow 2 child comments replies: [+] bleistift2@sopuli.xyz -6 points 2 years ago (1 child) 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. permalink fedilink source parent hideshow 2 child comments replies: [–] Lightfire228@pawb.social 16 points 2 years ago* (last edited 2 years ago) (2 children) 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) permalink fedilink source parent hideshow 4 child comments replies: [–] bleistift2@sopuli.xyz 1 point 2 years ago (1 child) 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 permalink fedilink source parent hideshow 2 child comments replies: [–] Lightfire228@pawb.social 1 point 2 years 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 permalink fedilink source parent [–] bane_killgrind@slrpnk.net 1 point 2 years ago Magic. Blasphemy. permalink fedilink source parent
[+] bleistift2@sopuli.xyz -6 points 2 years ago (1 child) 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. permalink fedilink source parent hideshow 2 child comments replies: [–] Lightfire228@pawb.social 16 points 2 years ago* (last edited 2 years ago) (2 children) 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) permalink fedilink source parent hideshow 4 child comments replies: [–] bleistift2@sopuli.xyz 1 point 2 years ago (1 child) 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 permalink fedilink source parent hideshow 2 child comments replies: [–] Lightfire228@pawb.social 1 point 2 years 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 permalink fedilink source parent [–] bane_killgrind@slrpnk.net 1 point 2 years ago Magic. Blasphemy. permalink fedilink source parent
[–] Lightfire228@pawb.social 16 points 2 years ago* (last edited 2 years ago) (2 children) 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) permalink fedilink source parent hideshow 4 child comments replies: [–] bleistift2@sopuli.xyz 1 point 2 years ago (1 child) 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 permalink fedilink source parent hideshow 2 child comments replies: [–] Lightfire228@pawb.social 1 point 2 years 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 permalink fedilink source parent [–] bane_killgrind@slrpnk.net 1 point 2 years ago Magic. Blasphemy. permalink fedilink source parent
[–] bleistift2@sopuli.xyz 1 point 2 years ago (1 child) 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 permalink fedilink source parent hideshow 2 child comments replies: [–] Lightfire228@pawb.social 1 point 2 years 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 permalink fedilink source parent
[–] Lightfire228@pawb.social 1 point 2 years 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 permalink fedilink source parent
[–] Gladaed@feddit.org 18 points 2 years ago* (1 child) Because stuff can own other stuff and be owned at the same time. Also, arcane jackarsery. Edit: if you want to give a function a pointer that it may change this may occur in a constructive way. I.e. replace an owned object. permalink fedilink source parent hideshow 2 child comments replies: [–] marcos@lemmy.world 5 points 2 years ago (1 child) Yeah... But it's usually a good practice to put a struct somewhere between your 30 levels of ownership. Exceptions exist, but they are not very common. Also, in C++, operators overloading may help you if you keep needing to write code like this. permalink fedilink source parent hideshow 2 child comments replies: [–] Gladaed@feddit.org 3 points 2 years ago (1 child) In C++ you should never have owning raw pointers. Unless you have a good reason™. Raw pointers are great, but not for ownership. permalink fedilink source parent hideshow 2 child comments replies: [–] qaz@lemmy.world 6 points 2 years ago* (last edited 2 years ago) (1 child) I just use unique_ptr 99% of the time permalink fedilink source parent hideshow 2 child comments replies: [–] Gladaed@feddit.org 4 points 2 years ago And you should. It even works for classes whose constructors your implementation cannot see, if you aren't a bitch about it. permalink fedilink source parent
[–] marcos@lemmy.world 5 points 2 years ago (1 child) Yeah... But it's usually a good practice to put a struct somewhere between your 30 levels of ownership. Exceptions exist, but they are not very common. Also, in C++, operators overloading may help you if you keep needing to write code like this. permalink fedilink source parent hideshow 2 child comments replies: [–] Gladaed@feddit.org 3 points 2 years ago (1 child) In C++ you should never have owning raw pointers. Unless you have a good reason™. Raw pointers are great, but not for ownership. permalink fedilink source parent hideshow 2 child comments replies: [–] qaz@lemmy.world 6 points 2 years ago* (last edited 2 years ago) (1 child) I just use unique_ptr 99% of the time permalink fedilink source parent hideshow 2 child comments replies: [–] Gladaed@feddit.org 4 points 2 years ago And you should. It even works for classes whose constructors your implementation cannot see, if you aren't a bitch about it. permalink fedilink source parent
[–] Gladaed@feddit.org 3 points 2 years ago (1 child) In C++ you should never have owning raw pointers. Unless you have a good reason™. Raw pointers are great, but not for ownership. permalink fedilink source parent hideshow 2 child comments replies: [–] qaz@lemmy.world 6 points 2 years ago* (last edited 2 years ago) (1 child) I just use unique_ptr 99% of the time permalink fedilink source parent hideshow 2 child comments replies: [–] Gladaed@feddit.org 4 points 2 years ago And you should. It even works for classes whose constructors your implementation cannot see, if you aren't a bitch about it. permalink fedilink source parent
[–] qaz@lemmy.world 6 points 2 years ago* (last edited 2 years ago) (1 child) I just use unique_ptr 99% of the time permalink fedilink source parent hideshow 2 child comments replies: [–] Gladaed@feddit.org 4 points 2 years ago And you should. It even works for classes whose constructors your implementation cannot see, if you aren't a bitch about it. permalink fedilink source parent
[–] Gladaed@feddit.org 4 points 2 years ago And you should. It even works for classes whose constructors your implementation cannot see, if you aren't a bitch about it. permalink fedilink source parent
[–] BradleyUffner@lemmy.world 15 points 2 years ago Pointers just point to memory addresses, and because pointers are stored in memory addresses, it just kind of naturally falls out that way. permalink fedilink source parent
[–] fibojoly@sh.itjust.works 12 points 2 years ago Pointer to pointer is fairly common stuff once you get serious with C++ but I've no idea what this abomination is supposed to even be, haha! permalink fedilink source parent
[–] Klnsfw@lemmynsfw.com 5 points 2 years ago Because int main(int argc, char** argv) permalink fedilink source parent
[–] mindbleach@sh.itjust.works 3 points 2 years ago (1 child) Because pointers are real. permalink fedilink source parent hideshow 2 child comments replies: [–] bleistift2@sopuli.xyz 1 point 2 years ago (1 child) That’s the best thing I’ve read in a while, and I’m only on page 2! permalink fedilink source parent hideshow 2 child comments replies: [–] mindbleach@sh.itjust.works 2 points 2 years ago (1 child) James Mickens does good work. permalink fedilink source parent hideshow 2 child comments replies: [–] bleistift2@sopuli.xyz 2 points 2 years ago If the Mossad wants your data, they’re going to use a drone to replace your cellphone with a piece of uranium that’s shaped like a cellphone That reads differently after 2024. permalink fedilink source parent
[–] bleistift2@sopuli.xyz 1 point 2 years ago (1 child) That’s the best thing I’ve read in a while, and I’m only on page 2! permalink fedilink source parent hideshow 2 child comments replies: [–] mindbleach@sh.itjust.works 2 points 2 years ago (1 child) James Mickens does good work. permalink fedilink source parent hideshow 2 child comments replies: [–] bleistift2@sopuli.xyz 2 points 2 years ago If the Mossad wants your data, they’re going to use a drone to replace your cellphone with a piece of uranium that’s shaped like a cellphone That reads differently after 2024. permalink fedilink source parent
[–] mindbleach@sh.itjust.works 2 points 2 years ago (1 child) James Mickens does good work. permalink fedilink source parent hideshow 2 child comments replies: [–] bleistift2@sopuli.xyz 2 points 2 years ago If the Mossad wants your data, they’re going to use a drone to replace your cellphone with a piece of uranium that’s shaped like a cellphone That reads differently after 2024. permalink fedilink source parent
[–] bleistift2@sopuli.xyz 2 points 2 years ago If the Mossad wants your data, they’re going to use a drone to replace your cellphone with a piece of uranium that’s shaped like a cellphone That reads differently after 2024. permalink fedilink source parent