Тёмный

Solving Common Pointer Conundrums - Loris Cro 

Zig SHOWTIME
Подписаться 12 тыс.
Просмотров 12 тыс.
50% 1

From Zig SHOWTIME #13
Subscribe to the Zig SHOWTIME Newsletter!
zig.show

Опубликовано:

 

4 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 28   
@charlesleninja
@charlesleninja 2 года назад
I just started laughing when he said "If you do not know what pointers are, I'm sorry but I'm just not gonna address that". Like, I knpw it wasn't meant, but it's still a good pun imo
@seanknowles9985
@seanknowles9985 Год назад
Your comment is failing to compile (line 3 > error: Like, I knpw it wasn't meant)
@jaybestemployee
@jaybestemployee 4 месяца назад
I thought sometimes it is simpler to just introduce the concept right away than to waste time explaining why not to do so. Concept of a pointer is not difficult if visualized well
@aleksszukovskis2074
@aleksszukovskis2074 3 месяца назад
@@seanknowles9985 parsing error: "Like, I knpw it wasn't meant" found on line 4
@araz911
@araz911 22 дня назад
pointer is a stupid abstraction, use raw adresses like a pro
@totheknee
@totheknee 3 года назад
I love the font you are using for the presentation code. Is it Proggy?
@ZigSHOWTIME
@ZigSHOWTIME 3 года назад
fonts.google.com/specimen/Press+Start+2P
@mephistotel87
@mephistotel87 2 года назад
Thank you! You are awesome!
@kanji_nakamoto
@kanji_nakamoto 3 года назад
Thanks 👍 keep sharing!
@diegosorte
@diegosorte 4 года назад
Thank you very much :)
@GLiBERN
@GLiBERN Год назад
At 14:20 it should be "you first unpack the optional", not "you first unpack the pointer".
@balen7555
@balen7555 4 года назад
At 17:54, it was said that the first line( *[*]MyType ) is a single pointer to a sequence of unknown number of "MyType"s but shouldn't it be a single pointer to a pointer to a sequence of unknown number of "MyType"s or am I mistaken here?
@kristoff-it
@kristoff-it 4 года назад
I'm not perfect at describing weird pointer combos, but in general the important part is that [*] is a pointer to an item, and all the brackets are telling you that by adding sizeOf(MyType) to that pointer you might have another instance of MyType. The way you can know that's the case or not is through a separate scheme (e.g. you have a second argument that conveys how many, or you know there's going to be a sentinel instance of MyType that tells you it's the end of the line). So with that in mind, *[*]T means that you have a pointer pointing to a pointer to T, so you have a **T, but you know that the pointer you get by dereferencing the initial value, might have other Ts in front of it. So if `a` is the original value, `a.*` is a pointer to T, `a.*[1]` is a T (index access to a pointer adds the size and dereferences). I hope that is a good explanation, also take a look at the compileLog messages in this snippet: zig.godbolt.org/z/EYzrqT
@balen7555
@balen7555 4 года назад
@@kristoff-it That was a very clear explanation, thank you!
@shoulderstack5527
@shoulderstack5527 3 года назад
@@kristoff-it I think your description in your response to Balen is correct, from looking at the Zig docs and the compileLog link you gave. But I think that means that your first two explanations (17:54) must be wrong... or at least a slip of the tongue. shouldn't they both have one more level of indirection than you said because the [ ] are also a dereference themselves.
@kristoff-it
@kristoff-it 3 года назад
@@shoulderstack5527 I think I might have used "sequence" and "sequence of pointers" a bit too liberally (to mean the same thing). Looking at the timestamp you linked, the first example is a single pointer that, when dereferenced, brings you to an array of pointers to MyType, but you don't know the length of that array. So to get to an instance of MyType (so not a pointer-to, but straight up a MyType value) you would write something like `my_var.*[2]`. The second example has the array in the outer layer, so you'd need to do `my_var[2].*` to obtain a MyType. Of course, this is all assuming the [*] have enough elements to accommodate for my example.
@shoulderstack5527
@shoulderstack5527 3 года назад
@@kristoff-it Also, I wanted to say 'Thanks so much' for these Zig Showtime and the Advent of Code videos. They really help to lower the cost of entry for someone like me. It means I can afford to devote some time to finding out if Zig is a good choice for me because you made it so easy to explore. Thanks!
@PLAYGAME-wj9bw
@PLAYGAME-wj9bw 8 месяцев назад
42:04 this doesn't seem to work as of today
@neohashi3396
@neohashi3396 11 месяцев назад
"if you know python.." goes on with an example where a slice in a reference and an assignment is a copy.. the exact opposite of python :D
@DooMWhite
@DooMWhite Год назад
Good stuff
@fjadron
@fjadron Год назад
ty nise video explaining pointers in zig . i have this idea hat insted of "&adress" it should be "adress." so the logic whit the pontiers would be easyer adress. *pointer .value insted of &adress *pointer . value
@HairyPixels
@HairyPixels 10 месяцев назад
How is an optional pointer the same size as a pointer? doesn't it need some flag to know if it's set or not?
@shilangyu
@shilangyu 9 месяцев назад
Null (address 0) represents the nil case of an optional value. This is similar to Rust's null pointer optimization where for instance the size of Option is the same as the size of &T. The 'nil' case can be safely represented as address 0 because pointers in rust (and zig) cannot be null.
@HairyPixels
@HairyPixels 9 месяцев назад
​@@shilangyuoh that's interesting, nil is reserved by virtue of it being illegal on raw pointers. Makes sense now thanks.
@pierreollivier1
@pierreollivier1 8 месяцев назад
@@HairyPixels Yeah basically Optional pointers in Zig or Rust are just syntactic sugar for branching on null. The equivalent in C would be : foo() { ... stuff happening. my_type *ptr = memory_reference_of_something(); if (ptr == NULL) // aka pointing at address 0. return (error); ... stuff happening. } The problem with null pointer is that they can be null, and if they are not systematically checked than it's a big deal, Optional, put that burden on the type system and the compiler. In Zig or Rust you can't access a pointer unless you are explicitly acknowledging that it can be null, either by handling the null case, or by assuming it to be unreachable.
@charleslegates9231
@charleslegates9231 5 месяцев назад
ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-VgjRyaRTH6E.html feature suggestion: suggest the fix in the compiler error like rust does
@mtoon0
@mtoon0 10 месяцев назад
36:42
@Iridescence
@Iridescence 4 года назад
Nice :)
Далее
A Look at Zig's Built-ins - Loris Cro
1:20:11
Просмотров 4 тыс.
Advanced Hello World in Zig - Loris Cro
34:51
Просмотров 8 тыс.
Women’s Celebrations + Men’s 😮‍💨
00:20
Просмотров 3,3 млн
НЕ БУДИТЕ КОТЯТ#cat
00:21
Просмотров 638 тыс.
Hare Programming Language
1:39:25
Просмотров 52 тыс.
When Zig Outshines Rust | Prime Reacts
23:31
Просмотров 140 тыс.
Zig in Depth: Memory Management
36:10
Просмотров 6 тыс.
Trying Zig Part 1
1:30:00
Просмотров 102 тыс.
What's a Memory Allocator Anyway? - Benjamin Feng
48:30
Why Async/Await in Zig isn't That Easy - Loris Cro
1:08:30
Programming with Math | The Lambda Calculus
21:48
Просмотров 198 тыс.