66
benj
6y

This morning finally pointers to structs in C finally clicked on my mind!!!🤯

80% of the C code that puzzled me now makes sense!! 🤗

Comments
  • 4
    Welcome to this side :)
  • 5
    @Cyanide Thanks! honestly thought I'd never make it! That I was too dumb and (no offense to anybody) was destined to stay in high level JS land!
  • 2
    @benj Congrats! Have a great journey ahead!
  • 4
    So here's the next mental exercise for you: start thinking about how C pointers relate to the references used in javascript, and then start wondering about how exactly javascript is interpreted by the browser and then run on the client machine ...

    It's a deep dark rabbit hole to explore. Have fun ^_^
  • 2
    @benj I'm still waiting for that morning
  • 0
    That sounds good. Very important step if you want to program in C further. How did the ice break? Double Linked List?
  • 7
    GG, now pointers to functions (mouhahaha)
  • 0
    @DefiniteGoose yes, but where is all the fun of function pointers then.
  • 1
    @DefiniteGoose well without pointers you can't store anything really, so you would be restricted to stack arrays / structs and can't modify anything passed to functions (since it must be passed by value without pointers). Pointers may be a bit finnicky at first but I they are unexpendable in the long run.

    Edit: function pointers rock!
  • 2
    @catadoxa that does sound like a dark deep rabbit hole!

    But I'm more interested in hardware and pointers mapped to registers mapped to gpio or buffers to devices like uart/spi/i2c or ad/da 😁

    @drekhi12 have been at it for a while so... Don't give up dude!!

    @RoodRallec I was watching a video about C structs and the guy sort of by mistake assigned a value directly to the memory location of the pointer...
    Then I was thinking who crazy person decided to use . AND -> to access structs! Why and when to use one!! Then I was reading about functions being able to read and modify external values if provided with pointers...
    And then woke up yesterday realizing how it all connected!! The reason for malloc and why it returned a pointer! The reason to pass pointers and function pointers around and how crazy freaking powerful and flexible that could be!!
  • 2
    @Hallelouia way ahead of you 😜 having done some functional programming (Elm, functional JS with redux, eLisp...) passing functions around sounds pretty natural already!

    @DefiniteGoose I feel your frustration man! I've been trying to learn C with probably 5 books and a bunch of videos and tutorials!! I'm not saying that is hard, but now that it sort of makes sense... the concept is not super intuitive and in introductory C it just sounds redundant... "Why not pass the value and be done with it!?"
    But taking into account the idea behind C (not writing assembly, control over memory and performance) it kind of starts making sense... And now I can't wait to put it to use, see how many CPU cycles I can save now!
  • 0
    @benj nice =)

    @DefiniteGoose I just love function pointers =)

    Also:
    https://fuckingfunctionpointers.com/...
Add Comment