What are pointers? (Odin)

Поділитися
Вставка
  • Опубліковано 10 січ 2025

КОМЕНТАРІ • 23

  • @karl_zylinski
    @karl_zylinski  Місяць тому +1

    My Odin book is out now: odinbook.com/ ✨

  • @FranzBrummer
    @FranzBrummer 2 місяці тому +15

    Looking forward to your book!

  • @chandragunawan4105
    @chandragunawan4105 2 місяці тому +5

    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 !

  • @BuLEEto
    @BuLEEto 2 місяці тому +7

    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. 😁

  • @ItsJustMeJerk
    @ItsJustMeJerk 2 місяці тому +1

    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++.

  • @kunimitanaka1079
    @kunimitanaka1079 2 місяці тому +3

    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.

  • @kencg6566
    @kencg6566 Місяць тому

    Clear explanation, thank you! Looking forward to the book. 👍✌️

  • @leeroy900
    @leeroy900 2 місяці тому +1

    Thanks

  • @channel11121
    @channel11121 Місяць тому +1

    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.

  • @bachwaregames
    @bachwaregames 2 місяці тому

    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.

    • @karl_zylinski
      @karl_zylinski  2 місяці тому +4

      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".

    • @FranzBrummer
      @FranzBrummer 2 місяці тому +2

      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.

    • @bachwaregames
      @bachwaregames 2 місяці тому

      @@karl_zylinski awesome, that cleared up some confusion. Thanks :)

    • @bachwaregames
      @bachwaregames 2 місяці тому

      @@FranzBrummer Sounds exactly like what Karl says. Thanks! :)

  • @ralphstube
    @ralphstube Місяць тому

    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
    }

  • @empathy_monster
    @empathy_monster 2 місяці тому

    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.

  • @tigrux
    @tigrux 2 місяці тому

    For someone new to Odin, the use of ^ instead of * looks odd.

  • @cycomkid
    @cycomkid Місяць тому

    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?

    • @cycomkid
      @cycomkid Місяць тому

      Any update karl?

    • @karl_zylinski
      @karl_zylinski  Місяць тому +2

      I'm afraid the steam version does not have source

    • @cycomkid
      @cycomkid Місяць тому

      @@karl_zylinski bought on Itch