top 70 comments

sorted by: hot top controversial new old
[–] 67 points 5 months ago (6 children)
  • [–] 3 points 5 months ago (3 children)

    Why would I want to be shown the concept of pointers by an eight year old?

  • source
  • parent
  • hideshow 3 child comments
  • load more comments (1 reply)
    [–] 64 points 5 months ago (14 children)

    Wait. It’s been a long time but shouldn’t be int*** -> int** -> int* -> int ?

  • source
  • hideshow 14 child comments
  • [–] 78 points 5 months ago (10 children)

    I think int*** is meant to be pointing at int**, but the image is just unclear about where everything is in perspective.

  • source
  • parent
  • hideshow 10 child comments
  • [–] 26 points 5 months ago (8 children)

    Pretty sure the image is clear:

    int*** -> int*
    int** -> int
    Int* -> int
    

    Clarity doesn’t mean correct. But that’s probably why it’s posted here. 🤷‍♂️

  • source
  • parent
  • hideshow 8 child comments
  • [–] 8 points 5 months ago

    int** is inside a TV, and persumably int* must be inside another TV(even though uts not edited in). The image perespective is showing one thing inside the other, inside the other. So when when int*** points the TV it reference int**, which reference int* which reference int. Its just edited very bad

  • source
  • parent
  • [–] 2 points 5 months ago (5 children)
  • [–] 4 points 5 months ago* (3 children)

    It’s to check to see if commenters know how to escape the symbol. Congratulations! You passed!

    Source: I made it up.

  • source
  • parent
  • hideshow 3 child comments
  • [–] 3 points 5 months ago

    That's not the end of the chain either, right?

    Because : int -> &int -> &&int

    Or can you not use the address operator like that? It also might be int& &, I failed cs2200 on this exact type of technicality

  • source
  • parent
  • [–] 100 points 5 months ago

    they used to call him the deref king back in college

  • source
  • [–] 39 points 5 months ago (1 child)

    Rumble Tumble Games in the wild

  • source
  • hideshow 1 child comment
  • [–] 29 points 5 months ago (1 child)

    Didn't expect to see the Drift King here

  • source
  • hideshow 1 child comment
  • [–] 9 points 5 months ago (8 children)

    So, googling it, the general premise is you should use smart pointers instead to avoid crashes. Got it.

  • source
  • hideshow 8 child comments
  • [–] 9 points 5 months ago (2 children)

    Smart pointers implies C++, which is not the right answer.

  • source
  • parent
  • hideshow 2 child comments
  • [–] 7 points 5 months ago (1 child)

    Unlike many other programming languages, which are often picked up on the go from tutorials found on the Internet, few are able to quickly pick up C++ without studying a well-written C++ book. It is way too big and complex for doing this. In fact, it is so big and complex, that there are very many very bad C++ books out there. And we are not talking about bad style, but things like sporting glaringly obvious factual errors and promoting abysmally bad programming styles.

    https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list

  • source
  • parent
  • hideshow 1 child comment
  • [–] 4 points 5 months ago* (last edited 5 months ago) (3 children)

    They all have footguns that cause different crashes.

    If you want to do explicit memory access without inevitable safety problems, you need Rust. That's the whole hype with Rust.

  • source
  • parent
  • hideshow 3 child comments
  • [–] 1 point 5 months ago* (2 children)

    But... per-process-isolation is a hardware feature, no?

  • source
  • parent
  • hideshow 2 child comments
  • [–] 7 points 5 months ago (2 children)

    Why should the left one in the rectangle be int**? It doesn't make sense to me, they are both clearly just int*

    What am i missing?

  • source
  • hideshow 2 child comments
  • [–] 7 points 5 months ago (6 children)

    Real talk: is there any practical use-case for T*** of any pointee type?

  • source
  • hideshow 6 child comments
  • [–] 22 points 5 months ago (5 children)

    Dynamically allocated multidimensional arrays.

  • source
  • parent
  • hideshow 5 child comments
  • [–] 12 points 5 months ago (1 child)

    Ah right, so that would be a 3D array.

    • T* is a single row of T
    • T** is a list of rows
    • T*** is a list of "layers" in the third dimension

    This would be incredibly hazardous to pass around as a bare pointer with no context, though. I'd expect to see this in a struct that, at minimum, also includes fields for the size of each dimension.

  • source
  • parent
  • hideshow 1 child comment
  • [–] 1 point 5 months ago (1 child)
  • [–] 3 points 5 months ago

    In the C programming language. Or do you mean which C project specifically? Because as Technus surmises in their response, it's usually a better idea to set up aliases (typedefs or heck, even #defines) so that you're offloading some of the mental strain keeping track of the layers, and that's likely to be what happens in production code.

    But the underlying data type is still T***.

  • source
  • parent
  • [–] 4 points 5 months ago

    C# delegates enter the chat and nod.

  • source
  • [–] 4 points 5 months ago (14 children)

    Now that explain the & part of the pointers that I never really understood.

  • source
  • hideshow 14 child comments
  • [–] 4 points 5 months ago*

    *x = dereference or "point to". Treats the variable x as containing a pointer value. Evaluates to a variable existing at the address in x.

    &x = reference or "get address of". Evaluates to the address of x.

    They're complimentary operators, so *(&x) cancels out and is equvalent to just x.

  • source
  • parent
  • [–] [S] 6 points 5 months ago (12 children)

    The & operator references the value.

    int i;
    int* p = &i;
    

    In C++, the & at the function argument makes it a reference type (safe pointer).

    void someFunction(int& refVal) {
        [...]
    }
    
  • source
  • parent
  • hideshow 12 child comments
  • [–] 2 points 5 months ago (11 children)

    As someone who likes working with higher level languages, I never understood the pass by reference or even referencing different pointers. It never stuck out to me as useful in what I want software to do. It’s too close to hardware.

  • source
  • parent
  • hideshow 11 child comments
  • [–] 9 points 5 months ago (7 children)

    if you're working with higher level languages you pass-by-reference all the time. give a list to a function to modify it? that's by reference. giving an event handler function to a framework? that's by reference. setting a property on an object? that's usually by reference.

  • source
  • parent
  • hideshow 7 child comments
  • [–] 0 points 5 months ago (6 children)

    the list is the helpful part to understanding it.

    it would be terrible if, with bar being a list and foo being a member of the list

     if foo in bar: return true
    

    modified the list. So yeah, you want to look at the list not edit the list, it's a pointer.

  • source
  • parent
  • hideshow 6 child comments
  • [–] 2 points 5 months ago

    Your example doesn't make sense to me. Why would you modify the entire list by checking if something is in it? Also, you can totally edit the list via a pointer, that's how you're supposed to edit the list if you want any performance. Otherwise you'd be copying the list on every modification, which is terribly inefficient

  • source
  • parent
  • [–] 1 point 5 months ago* (3 children)

    A pointer to the list would allow you to modify whatever's at that pointer's address though. If you want to look at the list and not edit it you pass by const reference 99% of the time (or you pass a copy) and if your language doesn't have that I don't like it.

  • source
  • parent
  • hideshow 3 child comments
  • [–] 2 points 5 months ago (2 children)

    I still don't get the point of pointers.

    I want my language to pass by reference. I give a variable to a function and the variable in the function scope should be a reference to the same place in memory as the original variable.

    How can pointers help me here? What value does it provide? Genuine question.

  • source
  • parent
  • hideshow 2 child comments
  • [–] 2 points 5 months ago* (1 child)

    I want my language to pass by reference. I give a variable to a function and the variable in the function scope should be a reference to the same place in memory as the original variable.

    I'm not even a C++ wizard or anything (though it's my most advanced language) so I'm not gonna argue that is good or bad, that sounds fine to me for a wide range of applications already.

    But the way is see it, pointers kinda allow you to use "raw memory" which is an actual thing that's gonna be handled by the program one way or another, and it's a way to relatively refer to memory for example. As some guy on stackoverflow put it "That guy at the end for the bar" vs "Bob" can be very useful. Especially when using data structures you don't know the size of at compile time.

  • source
  • parent
  • hideshow 1 child comment
  • [–] 2 points 5 months ago

    I had to implement drag and drop in a Windows application recently. Since you don't know the content type nor the size of the content, pointers has to be used, which makes sense. For the most part when working within the bounds of my own application, I haven't found a good use case for pointers. That could of course be because I am not used to thinking in that way.

  • source
  • parent
  • [–] 8 points 5 months ago* (last edited 5 months ago) (1 child)

    Most of the time you pass by reference for more outputs, or by const ref to avoid copying a big-ass data structure (which is not always straightforward, with structures smaller than a pointer, which are pretty big in 64 bits architecture, you lose more to the ref overhead than to the copy IIRC)

  • source
  • parent
  • hideshow 1 child comment
  • [–] [S] 1 point 5 months ago

    Reference values are quite useful, such as:

    double valOut;
    if (parseDouble(valOut) == 0) { //Argument of parseDouble is ref type, no & needed for input, no exceptions needed for error handling
        [...] //No error, code executed normally
    } else {
        [...] //Erroreus input
    }
    
  • source
  • parent
  • [–] 3 points 5 months ago (2 children)

    The placement of the labels is a bit sloppy but I think it tracks. The character in the middle (int*) is pointing at int, then the one on the left (int**) is pointing at the middle one (int*), etc

    What I want to know: what is that shirt and where do I get it?

  • source
  • hideshow 2 child comments
  • [–] 3 points 5 months ago

    that's not LaurieWired

  • source
  • [–] 3 points 5 months ago

    So, confusing, nonetheless.

  • source
  • [–] 4 points 5 months ago (1 child)

    Am I a computer scientist now?

  • source
  • hideshow 1 child comment
  • [–] 2 points 5 months ago (1 child)

    Uh I'm a charisma class (with unfortunate base stats) what's int

  • source
  • hideshow 1 child comment