Explaining Pointers Until I Go Insane

preview_player
Показать описание

Hello there! I've been wanting to talk about quirky pointers for a while. They make no sense sometimes.

Music used in the video:

This video was sponsored by Brilliant.
#Mults
Рекомендации по теме
Комментарии
Автор

Hello everyone! I've been doing some mix and match with my content style lately. Just trying new things. Let me know what you think :)

You’ll also get 20% off an annual premium subscription.

MultsElMesco
Автор

If a codebase has any of this stuff, you'll know it's been backdoored.

tuhkiscgibin
Автор

"say pointer again"
"fuck you"

vulnoryx
Автор

Who the hell would write the last one, without questioning their lives decisions.

eleinaedelweiss
Автор

You realize how complicated pointer syntax is when the best explanation of how to read complex statements is in a funny YT video

Suspaghetti
Автор

I honestly never had any issues understanding basic and more advanced pointer stuff, but THIS is some actual good stuff LMAO great video

Hallilo
Автор

Aight I'm never listening to the word "pointer" again

Spitfire
Автор

Honestly,
An array of functions sounds pretty dope.

Nevermind, an array of pointers to functions sounds pretty dope.

ry
Автор

to whoever reached a point in life where you ended up here or doing this, i really hope you find inner peace one day...

dipereira
Автор

im actually glad i found this video, you explained this well and now i know how to interpret those long lines

moneteezee
Автор

It all can get stupidly complicated as we've seen, but the syntax follows simple rules:

1. start reading from the identifier out
2. favor [ ] and ( ) over *

int (*(*x)[ ]) ( ):

- Following rule #1, we start at x
x
- The identifier x is alone in parentheses with an asterisk, so it is [§1] a pointer
*x
- Outside of the parentheses, we follow rule #2, so it is [§2] an array
(*x)[ ]
- We're left with an asterisk inside the parentheses, so [§3] pointers
*(*x)[ ]
- Outside of the parentheses, rule #2, [§4] functions
(*(*x)[ ])( )
- The functions return [§5] int
putting §1, §2, §3, §4 and §5 together:
x is (§1) a pointer to (§2) an array of (§3) pointers to (§4) functions that return (§5) an integer

Once you got the hang of it, you can rewrite the example like:
* [ ] * ( ) -> int
And stitch things together in a way that makes sense. "->" means "returns" and it's optional/redundant (anything immediately after parentheses in this notation is a return anyway)

Take the example of 5:34:
[ ] * * (* char, * (* char) -> * int) -> [ ] * (* * char, * ( ) -> * char) -> * int
Array of pointers to a pointer to a function that takes (a pointer to a character and a pointer to a function that takes (a pointer to a character) and returns a pointer to an integer) and returns an array of pointers to a function that takes (a pointer to a pointer to a character and a pointer to a function that returns a pointer to a character) and returns a pointer to an integer

It looks insane, but it's not that difficult to wrap your head around if you're writing it following those two simple rules

JoaoJGabriel
Автор

A programmer goes to therapy.
Therapist: Please tell me what you are scared of.
Programmer: I am scared of pointers.
Therapist: Okay, let me give you an array of pointers to handle them.
Programmer: 😱😱😱

NicolasChanCSY
Автор

Small tip for 1:20, you can order malloc like you did just by manually asking for each memory "sizeof(char) * 6..." but if you make a tipedef of your struct, you can just ask for a "sizeof(FUCKER)" and it will do the same, but far easier to read, and simpler

BaneDestabapillado
Автор

"For example, if I use this struct 'Fucker'" caught me completely off guard XD

My main takeaway from this video though is that as a C# dev for Unity, I shouldn't touch C++ with a 5 foot pole or else risk entering pointer hell.

James-netd
Автор

3:24 funnily enough this is how dynamic dispatch works in c++, each class (implicitly) creates a pointer to a global array of function pointers. This is also known as a virtual table or vtable/vftable as it contains the list of "virtual" functions for that class.

no-ldhz
Автор

6:00 Bro is holding the entire class inside his variable definition

The God Variable.

tvardero
Автор

C's syntax makes things excessively hard to parse, in other languages like C3 or more Pascal style languages (like Go and Odin) it's much more clear how these declarations compose

marcsfeh
Автор

Man, It felt awesome and confusing at the same time, but thanks to you I come to know the different use of pointers.

jatinsharma
Автор

this is what I understood from 3:10


- arr[0] -> func1 => int1
- arr [1] -> func2 => int2
x ->arr - arr[2] -> func3 => int3
- arr[3] -> func4 => int4
- arr[4] -> func5 => int5

halflight
Автор

I think, most of the confusion comes from the syntax.

For example, int (*(*x)[])()
in Rust, would be Box<Vec<Box<Fn() -> i32>>>

"Box" is Rust's pointer
i32 is Rust's int

norude