I just want to say a big thank you to you! You've really helped with me getting into and understanding Odin. I'm a go dev by default but have been having a blast with Odin, especially with raylib. Looking forward to reading your web book. 😁
One thing I recently learned the hard way while using pointers for the first time: if you accidentally let the memory that your pointer refers to get freed, then your pointer becomes bad (a dangling pointer), and now points to some random memory. The code might crash, or it might do something weird that drives you crazy. This confused me because I didn't understand the difference between a nil pointer and a bad pointer. At least Odin initializes the pointer as nil so it isn't bad to begin with (a wild pointer), unlike C/C++.
Thanks Karl. These short single subject videos are great. They are easily digestible which is especially important for subjects like pointers that are notorious for tripping up people new to programming. Keep up the good work.
I think you shouldn't use type-inference in the examples, because it hinders being able to pick up the same concept in multiple places to reinforce it. Especially in the first example, there was an opportunity to clearly show that there's an int, then right below it, is how you declare a pointer to it.
Thanks for the video! :) Looking forward to your book. Quick question. With my understanding, if you pass a struct to a function (not as a pointer) it will make a copy of that struct, like a value type, yes? So should we always be aware to pass it as a reference, even though we might not want modify the struct inside the function itself? Or is it fine to pass copies around, if we're not modifying it. Hope it makes sense.
It will not copy it if the struct is bigger than pointer size. Odin automatically sends it as immutable reference. I.e. a reference that you cannot modify. So you only need to pass by pointer when you want to modify it. Otherwise just pass by "value".
I might be wrong, but I think you're not supposed to change a function argument. So if you pass by value and change the struct in the function it is regarded as an error. The Odin compiler asks you if you wanted to pass a pointer instead. So I think technicall Odin doesn't make a copy for use in the function but a read only pointer or something like that.
Great lesson - playing around with the code and I see the passing by reference changes the value implicitly where as passing by value requires an explicit update to change the value - Being a real beginner to lower level is this something that is in your book and please can you do a video as it is a bit of a 'mind bender' for me: package pointers import "core:fmt" main :: proc() { number := 7 number_pointer := &number increment_number_point(number_pointer) fmt.println(number) fmt.println(number)// holds value number = increment_number_value(number) fmt.println(number) fmt.println(number)// holds value fmt.println(increment_number_value(number)) fmt.println(number) fmt.println(number) // doesn't hold value increment_number_value(number) // doesn't change value fmt.println(number)
I wanted to purchase your game on steam with source code. But i am not sure steam is providing source code or not. I can see that it's available on itch, but i don't want to use itch. Can you confirm if source code will be available in steam or not?
My Odin book is out now: odinbook.com/ ✨
Looking forward to your book!
Your contents makes Odin and low level programming in general less scary. Thanks a lot Karl ! Ill buy your book once it comes out for sure !
I just want to say a big thank you to you! You've really helped with me getting into and understanding Odin. I'm a go dev by default but have been having a blast with Odin, especially with raylib. Looking forward to reading your web book. 😁
One thing I recently learned the hard way while using pointers for the first time: if you accidentally let the memory that your pointer refers to get freed, then your pointer becomes bad (a dangling pointer), and now points to some random memory. The code might crash, or it might do something weird that drives you crazy. This confused me because I didn't understand the difference between a nil pointer and a bad pointer. At least Odin initializes the pointer as nil so it isn't bad to begin with (a wild pointer), unlike C/C++.
Thanks Karl. These short single subject videos are great. They are easily digestible which is especially important for subjects like pointers that are notorious for tripping up people new to programming. Keep up the good work.
Clear explanation, thank you! Looking forward to the book. 👍✌️
Thanks
Thank you so much!
I think you shouldn't use type-inference in the examples, because it hinders being able to pick up the same concept in multiple places to reinforce it. Especially in the first example, there was an opportunity to clearly show that there's an int, then right below it, is how you declare a pointer to it.
Thanks for the video! :) Looking forward to your book. Quick question.
With my understanding, if you pass a struct to a function (not as a pointer) it will make a copy of that struct, like a value type, yes? So should we always be aware to pass it as a reference, even though we might not want modify the struct inside the function itself? Or is it fine to pass copies around, if we're not modifying it. Hope it makes sense.
It will not copy it if the struct is bigger than pointer size. Odin automatically sends it as immutable reference. I.e. a reference that you cannot modify. So you only need to pass by pointer when you want to modify it. Otherwise just pass by "value".
I might be wrong, but I think you're not supposed to change a function argument. So if you pass by value and change the struct in the function it is regarded as an error. The Odin compiler asks you if you wanted to pass a pointer instead. So I think technicall Odin doesn't make a copy for use in the function but a read only pointer or something like that.
@@karl_zylinski awesome, that cleared up some confusion. Thanks :)
@@FranzBrummer Sounds exactly like what Karl says. Thanks! :)
Great lesson - playing around with the code and I see the passing by reference changes the value implicitly where as passing by value requires an explicit update to change the value - Being a real beginner to lower level is this something that is in your book and please can you do a video as it is a bit of a 'mind bender' for me:
package pointers
import "core:fmt"
main :: proc() {
number := 7
number_pointer := &number
increment_number_point(number_pointer)
fmt.println(number)
fmt.println(number)// holds value
number = increment_number_value(number)
fmt.println(number)
fmt.println(number)// holds value
fmt.println(increment_number_value(number))
fmt.println(number)
fmt.println(number) // doesn't hold value
increment_number_value(number) // doesn't change value
fmt.println(number)
}
increment_number_point :: proc(num: ^int) {
num^ = num^ + 1
}
increment_number_value :: proc(numb: int) -> int {
return numb + 1
}
I'm going through core:io but I'm pretty lost with getting user input from stdin. Maybe you could please consider putting a section in your book.
For someone new to Odin, the use of ^ instead of * looks odd.
It's a pointy thing 😀
I wanted to purchase your game on steam with source code. But i am not sure steam is providing source code or not.
I can see that it's available on itch, but i don't want to use itch.
Can you confirm if source code will be available in steam or not?
Any update karl?
I'm afraid the steam version does not have source
@@karl_zylinski bought on Itch