I'm a simple man. I see Anya, I upvote.
Programmer Humor
Post funny things about programming here! (Or just rant about your favourite programming language.)
Rules:
- Posts must be relevant to programming, programmers, or computer science.
- No NSFW content.
- Jokes must be in good taste. No hate speech, bigotry, etc.
here, have a peanut 🥜
I love peanuts!
Damn, OP’s on point tonight
No, he is on a pointer to a pointer to a point tonight
H-how did this meme clear up a confusion I have with ** pointers after all these years?
They're just pointer pointers!
Dang, that is so cool C can do that.
I know a guy who knows a guy who knows a guy
pointer pointers
wait until you learn about template templates in C++
Are the templates in the room with us right now?
That's actually a pretty good representation.
I think this graphic should be used on all CS courses from now on
int** int* interesting
Wait we can have pointers to other pointers? Wouldn't that be redundant?
In CUDA, the corresponding malloc
cannot return the pointer to the allocated memory as runtime CUDA functions all return error codes instead. So the only way to "return" the pointer then without a return statement is to have a pointer given to that function by address, which means that you'll have a pointer-to-pointer among its arguments.
Man, this is the type of interaction I used to love on Reddit, but haven’t seen in ages.
So it's sort of like "proxying" through pointers to enforce memory isolation?
I'm not entirely sure what you mean by memory isolation here, but the basic idea is that if you have a pointer to something then you know where it is located in memory and you can write in it, that's the whole idea of passing by address in C.
Now pointers themselves are merely variables. Yes they have a special meaning, they "point" to something and you can dereference them with the *
operator, but at the end of the day they're still variables. They have a physical existence in memory or CPU registers, and their content is simply the address to which you want to point. Once you accept this, then the idea of the address of a pointer (ie the location of the variable you're calling "pointer", and not the address it contains) is not strange anymore and you can perfectly have a pointer-to-pointer in order to, among other things, pass pointers by address.
that’s the whole idea of passing by address in C
Wait stop, so in other languages like C#, when you pass a variable into a function “by reference” is that just passing the pointer to the variable?
Have I been baited into using pointers my whole life?
Yes passing "by reference" is essentially the same as "by pointer" but with some syntactical sugar to make it easier to work with.