Cursed Coding: How the Void* Does Anything with Nothing

แชร์
ฝัง
  • เผยแพร่เมื่อ 29 พ.ค. 2024
  • Why is my channel called Voidstar Lab?
    Try Brilliant free for 30 days and get 20% off at brilliant.org/zackfreedman
    Support me on Patreon! / zackfreedman
    Support me on Thangs! thangs.com/zackfreedman
    Meet me and make friends! / discord
    Doomscroll me! x.com/zackfreedman
    A PROGRAMMING EPISODE?! Egads! Gadzooks! It's a good one. C and C++ feature a bizarre keyword: void* represents a memory address whose data are unknown or totally absent. This meaningless map to nothing enables function pointers, universal memory management, and event-driven architecture - all practical ways to code cleaner, faster, and with fewer bugs.
    This is an introductory programming video for beginners and intermediate coders. Advanced users have probably used tons of these already, but who knows? You might now know everything these five bizarre characters make possible.
    Credits:
    Interference SFX: Partners in Rhyme
    Other SFX: zapsplat.com
    Silly, silly stock footage: Storyblocks
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 1K

  • @goodboiadvsp3297
    @goodboiadvsp3297 9 หลายเดือนก่อน +836

    Id like to think that this video was based off of my question at the meetup 😁
    Edit:
    OMG THAT WAS MY QUESTION

    • @Andrew90046zero
      @Andrew90046zero 9 หลายเดือนก่อน +2

      Wait what?

    • @infectedrainbow
      @infectedrainbow 9 หลายเดือนก่อน

      @@Andrew90046zero It seems they went to the AMA and asked why the channel was called Voidstar.

    • @flabort
      @flabort 9 หลายเดือนก่อน

      ​@@Andrew90046zeroIn other words, @goodboiadvsp3297 was pleasantly surprised to see themselves in this video, when a circle of superfans were doing a Q&A at the convention.

    • @flabort
      @flabort 9 หลายเดือนก่อน +8

      3:05 in the video at Open Sauce

    • @Andrew90046zero
      @Andrew90046zero 9 หลายเดือนก่อน +2

      @@flabort oh right, duh! XD

  • @TheRamblingShepherd
    @TheRamblingShepherd 9 หลายเดือนก่อน +825

    I'm in my first week of an introductory C++ class. Listening to this video is like swimming in the ocean and feeling something warm and very solid brush your foot. There's something there; you can vaguely apprehend its shape. But the unknown holds primarily terror.

    • @frankhaugen
      @frankhaugen 9 หลายเดือนก่อน +30

      I'd say it's more like peeing in your pants to keep warm in a blizzard

    • @bachaddict
      @bachaddict 9 หลายเดือนก่อน +9

      good luck! I did quite a bit of embedded C and never used this, but understanding pointers is a must

    • @murdocII
      @murdocII 9 หลายเดือนก่อน +7

      It's a shark, those pointy stars bite like hell, try to be smart

    • @f3rny_66
      @f3rny_66 9 หลายเดือนก่อน +18

      starting to learn c++ is like starting to learn to build a house from atoms, except you are in acid and the house exist only in your head until you compile and realize that the house is actually a 5 headed alien because you pointed some electron to the wrong galaxy

    • @frankhaugen
      @frankhaugen 9 หลายเดือนก่อน +3

      @@f3rny_66 agreed 👍
      Now that C# is getting all the low-level niceties, and native C# IoT units are available, I'm starting to get rid of c/c++ knowledge

  • @greg4367
    @greg4367 9 หลายเดือนก่อน +170

    As a C programmer of 50 years I actually understood this topic perfectly... Until you tried to explain it. The best metaphor is no metaphor at all.

    • @purplelord8531
      @purplelord8531 9 หลายเดือนก่อน +14

      that's... a revelation to me
      i have had that exact experience before but you put it into words

    • @TheBlacktom
      @TheBlacktom 8 หลายเดือนก่อน +5

      As a non-programmer for whatever years I felt the same. Except I didn't understood it before and don't understand it now either.

    • @squelchstuff
      @squelchstuff 8 หลายเดือนก่อน +1

      So, that's a metaphor* ?

    • @LeoInterVir
      @LeoInterVir 8 หลายเดือนก่อน

      I never really understood pointers when I had a class in C++, now I'm scared of their power.

    • @kevin42
      @kevin42 7 หลายเดือนก่อน

      Golden rule of engineering

  • @filker0
    @filker0 9 หลายเดือนก่อน +273

    I use "void*" for a lot of things:
    * Data Hiding
    * Polymorphism
    * Generic memory operations
    I seldom use objects of "void*" to hold the address of functions because it bypasses argument validation and conversion. I use typedefs for callback function pointers and use "union" when I need a single function pointer to call functions with different interfaces depending on context. The generic button press would be "typedef void (* buttonPressedCallback_t)(void);" - No arguments/parameters, etc.
    Disclaimer: I'm a prehistoric C programmer from before the ANSI standard and C++ and lived through the C standard library "char*" to "void*" cataclysm.

    • @gedr7664
      @gedr7664 9 หลายเดือนก่อน +20

      you are a true wizard

    • @duncathan_salt
      @duncathan_salt 9 หลายเดือนก่อน +26

      I use void* for function pointers, because I don't actually write C myself - I decompile it. void* is lovely for function pointers when you don't have a clue what their signature is! lmao

    • @622.by.sunrise8
      @622.by.sunrise8 9 หลายเดือนก่อน +5

      Polymorphism is a blessing to modern programming.

    • @guigs4467
      @guigs4467 9 หลายเดือนก่อน +10

      "...and lived through the C standard library "char*" to "void*" cataclysm."
      Could you please elaborate?
      It seems interesting and my googlefu hasn't returned anything.

    • @FireCrack
      @FireCrack 9 หลายเดือนก่อน +10

      ​@@guigs4467long story, but long ago in the times of yore "void" wasn't a thing, and the standard way to have an arbitrary pointer was instead a char*

  • @henrivandenhatert2
    @henrivandenhatert2 9 หลายเดือนก่อน +313

    As an embedded engineer, please do more of this, it's great.

    • @littlefrank90
      @littlefrank90 9 หลายเดือนก่อน +6

      As a former java developer, I am scared of this kind of programming.

    • @Dent42
      @Dent42 9 หลายเดือนก่อน +11

      > As an embedded engineer
      Do you need help getting out?

    • @Lameless
      @Lameless 9 หลายเดือนก่อน

      ​@@littlefrank90As an c++ developer, help.

    • @michaelkilby4046
      @michaelkilby4046 9 หลายเดือนก่อน +3

      As an IT person who knows too little programming, this was awesome, do more!

    • @henrivandenhatert2
      @henrivandenhatert2 9 หลายเดือนก่อน +2

      @@Dent42 It is hard getting out, when I am embedded.

  • @UrknetLabradories
    @UrknetLabradories 9 หลายเดือนก่อน +133

    You possess a particularly potent proficiency for pinning us ADD people in place.
    Usually i'm off to try (and fail) something half way through an explanation of it but i never miss a second of one your videos.
    I know it's not a money maker but more coding when you can afford it would be awesome!

    • @Shoriken
      @Shoriken 9 หลายเดือนก่อน +2

      Me too!

    • @dsnineteen
      @dsnineteen 9 หลายเดือนก่อน +5

      ADHD gang represent 👊

    • @3903890
      @3903890 9 หลายเดือนก่อน +1

      Confirm here!

    • @devilsadvocate6989
      @devilsadvocate6989 9 หลายเดือนก่อน +1

      😂

    • @truckerdave8465
      @truckerdave8465 9 หลายเดือนก่อน +2

      AuAdhder reporting in, I second this!

  • @cooperised
    @cooperised 9 หลายเดือนก่อน +22

    I use void * a lot because I do firmware work in straight C. Super useful. But the biggest downside is that you almost immediately lose any of the mediocre type safety that the compiler provides. I use function pointers a lot too, they're pretty handy and retain type safety.

  • @TheDarkPreacher65
    @TheDarkPreacher65 9 หลายเดือนก่อน +94

    Zack, you are not known for making videos that typically bring tears to the eyes (unless you purposefully mispronounce something to trigger the comment trolls), but at the end of your video, where you talked about isekai elf mahiro-chan ~desuyone~, I was reminded of two of my own Patreon supporters who passed away and cried a little. Both of them were in my Discord server, and I couldn't bring myself to kick their accounts that their families never had the thought to delete after their passing, so I made a new role specially for them. They are now the server's Guardian Angels (I'm TheDarkPreacher, everything is kinda religion themed). One passed away so suddenly that I only found out he had been sick when I got a message on Patreon for an exit survey that simply said "He died." The other was the mom of one of my wife's friends, and we knew she was in poor health. It was very touching that you included isekai elf mahiro-chan ~desuyone~ in one last video before their patreon ran out. Here's hoping they are enjoying their life in a fantasy world and take any knowledge they gained from your videos to become an OP character that ends up ruling the world. Or at least, they are resting in peace.

    • @Hellmark
      @Hellmark 9 หลายเดือนก่อน +20

      After my wife died, it was kinda hard to cancel her Patreon subscriptions. After a certain point, I did have to make some budgetary changes (I got laid off after she died, and the job I got after that paid drastically less, plus going to a single income while still having about the same expenses can be hard. Like did you know car insurance for one person actually cost more than for a married couple combined?). What I ended up doing, was setting her name to reflect her passing by adding "RIP (1982-2021)" and running that for a few months before ending her subscription. I've not checked to see if anyone has done anything in honor of her (some of them I wasn't able to, because I don't have access to all of her accounts), but I hope they did.

    • @42436freak
      @42436freak 9 หลายเดือนก่อน +8

      Welp, now I cried. Thanks for that. Lost my best friend in November and it still hurts like hell. Loss is weird, comes in waves, and life is more fragile than we think.

    • @802Garage
      @802Garage 8 หลายเดือนก่อน

      So sad and very nice of him to mention.

  • @TheColorman
    @TheColorman 9 หลายเดือนก่อน +23

    I'm pretty sure parent class methods are supposed so work like how you describe void*, where classes inheriting from the parent promise to implement specific methods that are then called somewhere else regardless of what class it is; as long as it inherits from that specific parent.

    • @icebird76
      @icebird76 9 หลายเดือนก่อน +5

      That's what I was thinking. Inheritance should exist in C++, but maybe the complication was identifying the cartridge type, instantiating, and firing the method since no code is on them.

    • @Lord_zeel
      @Lord_zeel 9 หลายเดือนก่อน +8

      Yeah... I'm not sure exactly why he found dependency injection to be so much simpler than OOP for this. The described situation is practically exactly what OOP is for. It could be that the program was badly structured from the outset, and any refactor would have greatly improved it. It could be that he just isn't very good at OOP - he's admittedly not a programmer by trade, and OOP can be a bit daunting and it's easy to mess up. Functional programming is probably easier in this case, though I think a well designed object oriented approach would still be better and MUCH simpler for other people to use if you're going to share it.
      Truly, the greatest strength of OOP is in creating code that you intend for OTHER people to use. Abstraction, encapsulation, polymorphism. All that stuff is really important when you want to have code that you can make improvements to later without massively breaking stuff other people used it for, and it's much simpler for someone else to actually interact with as they only need to understand the interface.
      For your own personal code, or for core application code, it's usually too much overhead. But for a library or API? There's a reason that most popular modern programming language have OOP features, even if they aren't the star of the show.

    • @rbdesignsnh
      @rbdesignsnh 3 หลายเดือนก่อน

      @@Lord_zeel i was thinking much the same thing.

  • @carrottopevans
    @carrottopevans 9 หลายเดือนก่อน +83

    As a non-programmer who is just interested in making and 3d printing, this was so informative and held my attention the whole way through! Congrats on taking a leap to branch out while working on larger projects

    • @SeanCMonahan
      @SeanCMonahan 9 หลายเดือนก่อน +3

      Zack doesn't want to be... _typecast_ 😎

    • @802Garage
      @802Garage 8 หลายเดือนก่อน +1

      ​@@SeanCMonahanI see what you did there.

  • @raddaks2039
    @raddaks2039 9 หลายเดือนก่อน +8

    Yo rest in peace, isekai elf mahiro-chan. The voidstar patreon list will never be the same without you.

  • @loserssoldier
    @loserssoldier 9 หลายเดือนก่อน +14

    Zach, I think your show has been at its strongest when you’re teaching. My favorite episodes have consistently been the ones where you’re describing how tech concepts work, like the pick-and-place robot and the Diamond tip episodes. Would love to see more of this kind of thing!

  • @elideaver
    @elideaver 9 หลายเดือนก่อน +42

    It never occurred to me that void star meant void pointer lol

    • @namAehT
      @namAehT 9 หลายเดือนก่อน +10

      Same, I thought it was a pretentious name for a black hole.

    • @AileTheAlien
      @AileTheAlien 9 หลายเดือนก่อน +5

      😅@@namAehT yeah, I've always pronounced these as "pointers" not "star". (Or depending on what you're doing, you're talking about "address", "take the address of", "dereference", etc.)

    • @ethanjennings6442
      @ethanjennings6442 9 หลายเดือนก่อน +1

      I've also heard people pronouncing * as splat before. Void Splat Labs doesn't have the same ring to it.

    • @drdca8263
      @drdca8263 9 หลายเดือนก่อน +1

      @@ethanjennings6442not the same ring, but certainly *a* ring

    • @Ethan_Simon
      @Ethan_Simon 9 หลายเดือนก่อน +1

      ​@@namAehT tapped on this video from my recommendations expecting a physics video lol

  • @KaylaGraves
    @KaylaGraves 9 หลายเดือนก่อน +39

    As someone who uses C# a lot, that joke murdered me. I'm now a Java Fanfic coder. Updating Resume.

    • @GreenlandRobot
      @GreenlandRobot 9 หลายเดือนก่อน +7

      As a python developer I removed any reference to programmer from mine

    • @KaylaGraves
      @KaylaGraves 9 หลายเดือนก่อน +2

      @@GreenlandRobot brutal.

    • @BinaryRhyme.JackOfArts
      @BinaryRhyme.JackOfArts 9 หลายเดือนก่อน

      Lol. Yeah, loved that line.

  • @wherearemypants2213
    @wherearemypants2213 9 หลายเดือนก่อน +8

    void* in c is like duck-typing in python : it allows you to treat data however you please without explicit interfaces / inheritance.
    It does make the code less legible though, since the 'contract' you hold with said data is implicit.
    Blender's source code is actually is full of voidstars and it is a mess to work with.

  • @danielalexander8402
    @danielalexander8402 9 หลายเดือนก่อน +34

    10/10 for more programming based content. That’s the kind of content I’ve wanted to watch for a while.

  • @wowzande
    @wowzande 9 หลายเดือนก่อน +39

    C++ was the first language i learned . I havent touched it in years except modifying some stuff in marlin. Im rather surprised you did this video. I would like to know more . Keep up the good work!

  • @AWMLGaming
    @AWMLGaming 9 หลายเดือนก่อน +57

    i just imagined i was a delivery driver... worst day of my life

    • @tf5pZ9H5vcAdBp
      @tf5pZ9H5vcAdBp 9 หลายเดือนก่อน +2

      There's worse jobs out there so consider yourself blessed. I delivered pizza as a second job for a while and audio books are a game changer in that field.

    • @user-ep9zv4se3s
      @user-ep9zv4se3s 9 หลายเดือนก่อน +1

      I worked for Amazon. They could not manage delivery.

    • @brokeandtired
      @brokeandtired 9 หลายเดือนก่อน +2

      I am a food courier...whatever you imagine can't come close to how bad it can get.

  • @JashJhaveri
    @JashJhaveri 9 หลายเดือนก่อน +27

    You explained the utility of using pointers so nicely. Thank you!

  • @davespriter
    @davespriter 9 หลายเดือนก่อน +5

    this was the most interesting programming video i’ve ever seen. your enthusiasm for conveying the quirkiness of void* is a great example of what i love about this channel

  • @GeekySquidoo
    @GeekySquidoo 9 หลายเดือนก่อน +8

    I’ll admit, I don’t really understand or follow a lot of the programming stuff you do, but I love the way you present it so I really enjoy videos like this :)

  • @kleinlui
    @kleinlui 9 หลายเดือนก่อน +4

    I don't think void* for callbacks is a great idea, but for passing data through callbacks it's pretty much the only thing available. E.g. a download function also gets a void* provided by the caller, and in the callback you can cast it back to your own type and check e.g. what the download URL was, when it was started or whatever else you want to store in there.

  • @ConstantStream69
    @ConstantStream69 6 หลายเดือนก่อน +1

    "I love to learn, but hate being taught" such a simple concept, but one that had never crossed my mind before. 100% relatable

  • @evanbarnes9984
    @evanbarnes9984 9 หลายเดือนก่อน +7

    Hey! Please do more of this! Way too many of my favorite creators like you skip over the programming because they're worried that people will find it boring. Maybe some do, but the rest of us ate fascinated and need more!

  • @LevelUpYourFandom
    @LevelUpYourFandom 9 หลายเดือนก่อน +8

    i actually liked this episode a lot. im down for topics that are tangential to your 'norm' but still relevant to the norm, and in your classic hilarious style. great job

  • @namAehT
    @namAehT 9 หลายเดือนก่อน +3

    Holy fuck I was just re-watching random old videos looking for that sweet Voidstar dopamine hit.

  • @justinlynn
    @justinlynn 9 หลายเดือนก่อน +2

    [slaps side of compiler] This no-thing can do SO MUCH any-thing - [quietly] but, mostly, it's just SIGSEGVs.
    But seriously, this is great! I love this :D

  • @strelkomania
    @strelkomania 9 หลายเดือนก่อน +30

    I actually really enjoy these types of videos from you ! As well as your editing style, it helps my shirt attention span lol

    • @tdgchan
      @tdgchan 9 หลายเดือนก่อน +4

      Shirt attention span? Mine has to be a napkin then...

    • @strelkomania
      @strelkomania 9 หลายเดือนก่อน +2

      @@tdgchan 😂😅 I definitely meant short* but your reply is too awesome, I won't fix my typo

    • @collectorguy3919
      @collectorguy3919 9 หลายเดือนก่อน +4

      @@strelkomania I took "shirt" attention span as an intentionally ambiguous typo of "short" or "shit"

    • @strelkomania
      @strelkomania 9 หลายเดือนก่อน

      @@collectorguy3919 😂i love that

  • @zilog1
    @zilog1 9 หลายเดือนก่อน +16

    Omfg please more of these videos. You make programming actually make sense. You have no idea how valuable you are to people wanting to learn.

  • @AB-Prince
    @AB-Prince 9 หลายเดือนก่อน +5

    😂 as a hobbyist c# programmer. "cup of error" just makes me crack. I need a cup of error for my computer desk now.

  • @BinaryRhyme.JackOfArts
    @BinaryRhyme.JackOfArts 9 หลายเดือนก่อน +5

    Loved the vid. The void* is great for prototyping, but I shudder to think of it being used in large production code bases, lol. I've become a fan of C# in my dotage, and some of the constructs like interfaces to allow for polymorphism without baroque class inheritance trees.
    Keep on keeping on. Love your stuff.

  • @floorpizza8074
    @floorpizza8074 9 หลายเดือนก่อน +3

    Zach, I haven't written any code in over 20 years. Even so, you're such a great teacher, I understood everything you said. Have you ever considered a "Learn Programming From Scratch" series where you do your own take on Dave Mark's classic books "Learn C On the Mac" and "Learn C on the PC"? For those not familiar, Mark's books were famous for taking someone with zero knowledge of programming and getting them proficient in C in an easily understood way.
    As I said, you're such a great teacher, you could take someone that has never done a "Hello World" and have them competent in C in short order. And since Dave Mark hasn't updated his books in years, he has left a *Void* to fill.
    I'd even pry open my wallet to take such courses from you.

  • @consciouscode8150
    @consciouscode8150 9 หลายเดือนก่อน +7

    Fun fact: int `*foo; (ignore the ` - youtube has no escape sequences) is technically more correct because the star is associated with the name, not the type. You can see this more clearly when you declare multiple pointer variables: int `*foo, `*bar, baz; (baz here is an ordinary int). The idea is that the value of that variable *dereferenced* is int.

    • @Lord_zeel
      @Lord_zeel 9 หลายเดือนก่อน

      I prefer to think of it as "the type of 'foo' is 'pointer to an int'" - the actual value at foo is the address of something, so the data type of foo is pointer. Thus just as 'int foo' is an int, 'int* foo' is a pointer to an int. Saying 'int *foo' seems nonsensical to me.

    • @RiderAnton
      @RiderAnton 9 หลายเดือนก่อน +2

      ​​​@@Lord_zeelthe problem is that int* does not cause all following declared variables to be int pointers: `int* var1, var2, var3;` is a common trap in C/C++ exactly because of that. You may think var2 and var3 are pointers, but they're actually integers.
      If you want var2 and var3 to be pointers in that line, you /must/ write it as `int *var1, *var2, *var3;`

    • @isodoublet
      @isodoublet 8 หลายเดือนก่อน

      @@Lord_zeel It actually is the only thing that makes any sense. Granted, it only makes sense because C's variable declaration syntax is absurd, but it does make sense. The idea is that "declaration follows use" -- the syntax for declaring a type mirrors how you use that type. So for example you declare an array like int a[3];, which is also how you index into it. Same goes for pointers, you write int *a; because a is a variable that, when dereferenced with *, will produce an int.
      I think there's not a single person in the universe who in 2023 thinks this syntax was a good idea (including the original designers of C), but we're stuck with it. There's two choices from here: one is to reject this 'feature' of C and try to pretend it has a more normal declaration syntax. You'll have to make some house rules (like never declare more than one variable in the same statement), and it'll always carry some residual wonkiness, but you can do it. This is where you write int* a. The other choice is to embrace the suck and accept that this is the way the language was designed, and try to work with it instead of against it. You'll have to adjust your thinking, but you won't have to make any house rules, and it'll always work consistently. This is where you write int *a.

  • @mskiptr
    @mskiptr 9 หลายเดือนก่อน +4

    After dabbling in type theory, I now find Idris | Haskell | Rust 's Void much neater. It has this curious property that there's no expression that would be of this type. Useful for marking functions that do not return - that is loop or do jump somewhere but will never come back.
    But when a function does return, just nothing of value, its return type can be Unit - which has exactly one possible value (like the 0-length tuple). Sort of a placeholder that roughly corresponds to the void return type of C-like languages.
    And if you're doing theorem-proving, Void is an impossible proposition while Unit corresponds to something trivially true.

    • @computationaltrinitarianis1451
      @computationaltrinitarianis1451 9 หลายเดือนก่อน +1

      Yay. A person that uses a dependently typed language. There are dozens of us.
      I recommend you checkout Lean 4 if you haven't already. The codebase of the language itself is quite fun to read as well since the compiler is (mostly I think) self hosted.

    • @isodoublet
      @isodoublet 8 หลายเดือนก่อน +2

      I'm not much too fussed with what a type is called, but I do have one gripe with how void works in C/C++, which is that it isn't a real type. You can't make a variable of type void and assign it the only possible value -- the language says that doesn't mean anything so clearly you would never want to do it. Except C++ also gives you templates to write code that works generically, and it would be damn convenient to treat void like any other type, the way Haskell's Unit works.

    • @mskiptr
      @mskiptr 8 หลายเดือนก่อน

      ​​@@computationaltrinitarianis1451
      Sadly YT has hid your comment (it's still invisible for me, unless I sort everything by 'newest').
      As for Lean, it's on my radar, though I don't know much about it nor about Agda.
      The first time I tried to learn Coq I didn't understand enough of how it works under the hood to really use it. I need to try again!
      But recently a friend has told me about Natural Number Game which is built around Lean so that will likely be my next step.

  • @ZenithWest169
    @ZenithWest169 9 หลายเดือนก่อน +2

    Yeah my professors hated my coding style. I absolutely loved my array of void*'s how I'd loop over them changing data. Had one class where your graded on actual performance. Get your program to run in 10 minutes=70, 7.5min=80, 6min=90 and sub 5min was a 100. Me and the prof competed and I beat him in all but one project pushing sub 30 seconds. He said he hated my code with a passion but couldn't argue how efficient it was.

  • @engineer0239
    @engineer0239 9 หลายเดือนก่อน +1

    Beein studying computer science for 2 years now, and this Video opened my eyes on how Event driven Architecture works on C++. We only briefly discussed how it works in Java, but this video was a very useful addition! Thank you so much!

  • @WhoWatchesVideos
    @WhoWatchesVideos 9 หลายเดือนก่อน +6

    Now I'm _really_ concerned about how you managed to have a callback as a method devolve into chaos such that replacing it with a bare function solved your problems.

  • @williamnollert486
    @williamnollert486 9 หลายเดือนก่อน +9

    Can’t wait for the bigger project vids but love this content as well. Keep it coming!

  • @christopherkopperman8108
    @christopherkopperman8108 9 หลายเดือนก่อน +2

    For non-coders a pointer is very similar to how pronouns work. A pronoun doesn't describe a thing (the nouns and adjectives do that) a pronoun refers to the noun that describes the thing. The same reason they do it in coding is the same reason we do it in any language, describing a thing makes a new instance of that thing while referring to a thing does not. This makes it easier in both computation and on one's cognitive strain. For any confused about houses and such in Zach's description. A pointer is basically saying "Hey remember that thing that I previously established, often in detail? Yeah, talking about it again."

  • @Ishsa
    @Ishsa 9 หลายเดือนก่อน +2

    I just love learning this stuff. I'm a musician and love making my computer do math, but I have a tough time learning real programming skills, so this kind of thing really helps to open up my idea factory

  • @LucasTheDrgn
    @LucasTheDrgn 9 หลายเดือนก่อน +3

    As someone who taught themselves python and then ended up using it for college projects over the languages i had to pay to be taught, I do find it funny that this video starts with ragging on python and then goes on to explain a concept that is intrinsic and intuitive in python. I have replaced the built-in print function because i wrote a program and then later decided i wanted to do more with the logs than just output to stdout. I may have actually done this as part of my college homework so I could test it by outputting to stdout and then turn it in with it outputting to a file, as the professor wanted.

  • @loganq5152
    @loganq5152 9 หลายเดือนก่อน +3

    Void Star is also the name of my favorite book.

  • @Windgazer42
    @Windgazer42 9 หลายเดือนก่อน +2

    I think that was a relatively clear definition of what a void * does, but I don't know C all that well. All I kept thinking at first was, what's so special about that, we do all of that stuff all of the time in Javascript.
    But thinking back of when I was doing Pascal and even for a short time some C, it would've been great to have known about this back then!

  • @DiThi
    @DiThi 9 หลายเดือนก่อน +2

    If you like both Python and very low level bare metal programming, you may like Nim. It looks like Python, it has many more features than Python (like generics, macros, function overloading, custom operators), it's as fast as C, and it compiles to C/C++ so you can use in about *anything* like obscure microcontrollers that only have a crappy C compiler. Using ARC as memory manager it inserts the mallocs/frees automatically where needed and it doesn't have GC pauses. It's very easy to interface with C, C++ and ObjC libraries. It also compiles to JS but in most cases it's much better to tell it to use emscripten.

  • @U20E0
    @U20E0 9 หลายเดือนก่อน +5

    You should’t use void* for function pointers. You should use actual function pointers ( the syntax is ret_type (*name)(args) ), that way the compiler and people reading the code will be able to tell what the callback function should look like.

    • @GabrielSoldani
      @GabrielSoldani 7 หลายเดือนก่อน

      It’s actually undefined behavior to cast function pointers to void*. This isn’t much of a problem in modern PC architectures, but void* is a type for _data_ pointers. You can imagine a machine where code is stored in ROM and data is stored in RAM that the types used to address them could be completely different, and of different sizes. This happens in IA-64 and 8086 16-bit real mode, apparently. It _is_ legal to convert function pointers to any other function pointer type, so if you want to store a pointer to any function, you can cast it to void (*)(void).

  • @Shoefly007
    @Shoefly007 9 หลายเดือนก่อน +3

    Great episode! Thank you for simultaneously melting my brain and making me feel less stupid for always struggling with OOP.

  • @RyushoYosei
    @RyushoYosei 9 หลายเดือนก่อน +1

    You mention that whole bit with the Quagsire, and the funny thing, Gamefreak did that very thing in Pokemon Sun and moon, using the same model fully duplicated for various scenes, a fully independent copy of the model, even though there was no real differences, rather then just one model they could reference and set a state too. According to twitter and some other places its to "Make it load faster." Since it was right there with everything else, rather then being something it had to pull from another location.

  • @andykphoto
    @andykphoto 9 หลายเดือนก่อน +2

    As an IT Professional for the last 20 years, and a recovering computer science student, I deeply enjoyed this video. I mean, most of them are pretty awesome, but this one hits different. 😸😹

  • @hikirj
    @hikirj 9 หลายเดือนก่อน +11

    Wow. Absolutely loved this video Zack! Would love to see more coding-oriented videos like this

  • @_gamma.
    @_gamma. 9 หลายเดือนก่อน +6

    I hadn’t connected the lab name, it’s pretty genius. I enjoyed this video, even if I am a python “programmer” 🐍

  • @xphreakyphilx
    @xphreakyphilx 9 หลายเดือนก่อน +2

    Thanks for reminding me why I prefer Rust over C/C++. In Rust basically every time you'd use a void* you can deal with it in a type-safe way.

    • @isodoublet
      @isodoublet 8 หลายเดือนก่อน

      C++ has type safe alternatives too.

  • @ACoupleStoners
    @ACoupleStoners 9 หลายเดือนก่อน +1

    Not only did you keep me hooked the whole time, I went back a second time to understand better. You're videos are incredible.

  • @MachFarcon
    @MachFarcon 9 หลายเดือนก่อน +3

    First, you did an awesome job explaining things at a high level, though I will admit that while I'm not a programmer, I have dabbled in scripting for my sys admin job so it was somewhat easy for me to get what you were putting down. Baller job!
    Secondly, it might just be the fact that I'm working on building the magic system for my TTRPG, but your explanation also felt like you were explaining the inner workings of conceptual magic, and it was awesome. To an average non-magical (or non-technical) person, it probably would be like "those indeed are those spell-words. I understand the concept you explained, but still spell-words." Which is doubly awesome. Keep up the good work!
    And if the algorithm permits (praise be), I wouldn't mind seeing more code in your future videos.

  • @devjock
    @devjock 9 หลายเดือนก่อน +6

    12:47 Zack, you know your audience is "special" enough they can detect a rickroll by the video-ID alone..

  • @justinbanks2380
    @justinbanks2380 6 หลายเดือนก่อน

    Please continue doing these type of teaching videos from time to time about whatever topics you choose.
    This was great. I finally got an answer or two to the exact difference and use case for some terminology and things in code that I've been using for years now but never fully understood

  • @kadet1090
    @kadet1090 9 หลายเดือนก่อน +1

    On my studies we always joked that skill of the programmer / hardness of the program could be expressed with "star rating", i.e. maximum number of "stars" attached to any type (especially beloved void) in the program. Of course usage of such indirect reference must not be just for show, but have practical use. For now, 3 stars is all I've got.

  • @dip8
    @dip8 9 หลายเดือนก่อน +5

    wow the video was amazing! good job

    • @ShadowMaelstrom
      @ShadowMaelstrom 9 หลายเดือนก่อน +1

      Amazing you can watch a 21 minute video in under a minute

    • @dip8
      @dip8 9 หลายเดือนก่อน

      @@ShadowMaelstrom im just fast dw abt it

    • @ShadowMaelstrom
      @ShadowMaelstrom 9 หลายเดือนก่อน

      @@dip8 bet the ladies love you

    • @dip8
      @dip8 9 หลายเดือนก่อน

      @@ShadowMaelstrom lol

  • @SlimyRedstone
    @SlimyRedstone 9 หลายเดือนก่อน +3

    We want more of you explaining programming concepts ! (By the way I didn't know the power that void* has...)

  • @bobbie9066
    @bobbie9066 9 หลายเดือนก่อน +2

    I hope you get a good response to this because I love the passionate, practical way you explain stuff AND I want you to have time to work on bigger projects!
    But also it's been a while since I've touched any C, so I'll definitely enjoy rewatching this

  • @chadcrocker
    @chadcrocker 9 หลายเดือนก่อน +1

    I started my career with C and C++. Hearing all of this brought back great horror memories! Keep doing what you do!

  • @dip8
    @dip8 9 หลายเดือนก่อน +3

    4:17 I already feel offended lol

  • @mattmakesmachines
    @mattmakesmachines 9 หลายเดือนก่อน +4

    I’ve never clicked on a notification so fast lmao

    • @strelkomania
      @strelkomania 9 หลายเดือนก่อน

      same 😂

  • @lamMeTV
    @lamMeTV 9 หลายเดือนก่อน +1

    The first 17 minutes really went in one ear and out the other. But then the example of the modular remote thingy really made it click. I love void stars now! Way easier than oob

  • @dolfandringa
    @dolfandringa 9 หลายเดือนก่อน +1

    I like how the video evolved into loose coupling, event driven architecture, and functional vs object oriented programming all from the void pointer.

  • @honzas.5234
    @honzas.5234 9 หลายเดือนก่อน +10

    I would definitely want to see more of the code in your project videos.

    • @strelkomania
      @strelkomania 9 หลายเดือนก่อน

      agreed !!

  • @user-fk6sy7if8e
    @user-fk6sy7if8e 9 หลายเดือนก่อน +7

    I like your funny words computer man.

  • @user-zj8hf1js4z
    @user-zj8hf1js4z 9 หลายเดือนก่อน

    I can't believe it. You finally explained pointers in a way that makes sense. I've struggled with this concept for five years, no explanation in any book, wiki, comment, stack overflow, chatGPT question has ever been able to do. I gave up on C because of this. Thank you. I will, perhaps, dip my toes hesitantly back in those waters.

  • @gamemeister27
    @gamemeister27 9 หลายเดือนก่อน +1

    Ok it took me a while to get exactly how the advantage manifests, but the bit that kicked it into my skull was the bit about the button being a dumb thing that doesn't have to know what it's referencing, it just calls the voidstar, and whatever is there is there.

  • @HyperDash
    @HyperDash 9 หลายเดือนก่อน +3

    better explanation of literally any cs concept than any of my tenured professors over the last 4 years
    and this is why my degree was completed on the combined efforts of random internet people with strong accents and MIT OCW
    and also why i graduated with a cs degree and immediately went into the field of art 😂

  • @LumanilTheMentor
    @LumanilTheMentor 8 หลายเดือนก่อน

    Just found your channel Zack, and i dont even 3D print, but i cant stop watching. You're a genuine joy to watch! Cant wait for the next one.

  • @tcurdt
    @tcurdt 9 หลายเดือนก่อน +1

    I am impressed. Who would have thought you can talk almost 22 minutes about such a simple thing as a void*

  • @andrewchapman2039
    @andrewchapman2039 9 หลายเดือนก่อน +2

    Dude you're expanding my mind right now and I didn't sign up for that. I had things to do today and now I'm thinking about Void*-mediated modularity in physical systems.

  • @m4rt_
    @m4rt_ 9 หลายเดือนก่อน +1

    I noticed some slight inaccuracies in what you explained.
    A function with the return type void returns no value.
    While a function with a return type that isn't void has to return something.
    Though a a function with a return type void * has to return something, specifically a pointer, but the data type for that pointer can be anything.
    So with that you can do something like:
    #include
    void * return_stuff(uint32_t flag) {
    switch (flag) {
    case 0:
    return malloc(sizeof(uint8_t));
    break;
    case 1:
    return malloc(sizeof(uint16_t));
    break;
    case 2:
    return malloc(sizeof(uint32_t));
    break;
    case 3:
    return malloc(sizeof(uint64_t));
    break;
    default:
    return NULL;
    break;
    }
    }
    This has been used a lot in the past, and has some use cases today, but it's a good idea to avoid it, and rather use existing types, or custom types.
    For example you can make a struct with an union, and use an enum to say what it is. e.g.
    #include
    typedef struct {
    enum {
    KIND_U8,
    KIND_U16,
    KIND_U32,
    KIND_U64,
    KIND_NONE,
    } kind;
    union {
    uint8_t* u8_ptr;
    uint8_t* u16_ptr;
    uint8_t* u32_ptr;
    uint8_t* u64_ptr;
    };
    } Stuff;
    and then you can use it like this:
    #include
    Stuff make_stuff(uint32_t flag) {
    Stuff stuff;
    switch (flag) {
    case 0:
    stuff.kind = KIND_U8;
    stuff.u8_ptr = malloc(sizeof(uint8_t));
    *stuff.u8_ptr = 0;
    return stuff;
    case 1:
    stuff.kind = KIND_U16;
    stuff.u16_ptr = malloc(sizeof(uint16_t));
    *stuff.u16_ptr = 0;
    return stuff;
    case 2:
    stuff.kind = KIND_U32;
    stuff.u32_ptr = malloc(sizeof(uint32_t));
    *stuff.u32_ptr = 0;
    return stuff;
    case 3:
    stuff.kind = KIND_U64;
    stuff.u64_ptr = malloc(sizeof(uint64_t));
    *stuff.u64_ptr = 0;
    return stuff;
    default:
    stuff.kind = KIND_NONE;
    return stuff;
    }
    }

  • @johnschewe6358
    @johnschewe6358 9 หลายเดือนก่อน +1

    void* is available in C#, but it's only available in unsafe (unmanaged) sections of code. The managed equivalent is IntPtr, which refers to the pointer value itself and doesn't have any concept of what sits at that address.

  • @KiemPlant
    @KiemPlant 9 หลายเดือนก่อน +1

    During my 1,5 month long break from uni, this video was a nice reminder that I at least didn't forget the basics of programming lmao.

  • @scripter1282
    @scripter1282 9 หลายเดือนก่อน

    I now attach "on complete" conditions and output variables to the ends of some of my OOP code because of this video. any task can now start any other task, and more easily pass data between them. very helpful!

  • @scottwilliams895
    @scottwilliams895 9 หลายเดือนก่อน +1

    Zack, your writing & delivery is brilliant! I'll watch any video you make on any topic; code, 3d, cyborg, home renovation, anything!
    One day I hope to hear my name in those credits

  • @LuxmasterCZ
    @LuxmasterCZ 9 หลายเดือนก่อน

    This vid was very fresh. I like when you talk concepts more than things, good job!

  • @isthattrue1083
    @isthattrue1083 9 หลายเดือนก่อน

    Been waiting on this. Thank you Zack.

  • @802Garage
    @802Garage 8 หลายเดือนก่อน +1

    It's funny because at my college nobody called it star we always referred to it as pointer. So despite 5 years of programming classes, long story, it never occurred to me your channel was name after a void pointer, hahaha. Even a ** was referred to as a pointer pointer. People did say star sometimes of course, but saying asterisk was more common by my recollection. Fun stuff.

  • @catsfan2937
    @catsfan2937 9 หลายเดือนก่อน

    I think this video had the least useful (but most entertaining) explanations of a void pointer I've ever heard :)
    Would love more videos like this! Especially the devlog bits about your old prototypes are very cool

  • @AndyOz2012
    @AndyOz2012 9 หลายเดือนก่อน

    Great video! I recently have started to feel like I have a solid grasp of the object oriented programming style, now upon learning what EDP is its time to learn some more!

  • @bakedbeings
    @bakedbeings 9 หลายเดือนก่อน +1

    I was horrified when I recognised the trucks-polymorphism analogy at the start, but only because in C++ (which I like) it means void pointers and other filthiness to do it.

  • @jameskelly827
    @jameskelly827 9 หลายเดือนก่อน

    This is now my favorite video of yours. Please do more code videos!

  • @benfrost5317
    @benfrost5317 9 หลายเดือนก่อน

    This video was Fantastic. Please make more of these!

  • @granger7664
    @granger7664 8 หลายเดือนก่อน

    My favorite video of yours so far! More code videos 🙏🏻

  • @pwarrow8858
    @pwarrow8858 8 หลายเดือนก่อน

    I really enjoyed this type of video. Please do more of these.

  • @SkateSoup
    @SkateSoup 9 หลายเดือนก่อน +1

    This video was a thousand times more coherent than my first semester of C in college.

  • @Bp1033
    @Bp1033 9 หลายเดือนก่อน

    Yes! More code stuff! I never thought to assign a pointer void before, I'm going to try this out.

  • @dooterino
    @dooterino 9 หลายเดือนก่อน

    I'm an embedded firmware engineer by trade and I only just realized a couple weeks ago that Voidstar == (void*) while helping out a coworker with some C work, now this video comes along! Wild!

  • @elitemantis
    @elitemantis 9 หลายเดือนก่อน

    I coded in C/C++ for like 15 years, haven't used it in another 15 and now I totally forgot that void* even existed. Thanks for that blast from the past!

  • @Flargenyargen
    @Flargenyargen 9 หลายเดือนก่อน

    I hate that a lot of my favorite tech-adjacent people treat code like a vampire treats a crucifix. That's hugely entertaining to me. This one rocks, man. Keep doing the good stuff.

  • @SmoinsLP
    @SmoinsLP 9 หลายเดือนก่อน +1

    I cant believe I lived without this until now, cant wait to try using it and giving up after 5 mins

  • @Xx32123
    @Xx32123 9 หลายเดือนก่อน

    Please do more of videos like these where you teach and stuff I love them!

  • @JO-sg7wk
    @JO-sg7wk 4 หลายเดือนก่อน

    very good video, hated OOP in HS never really got the assignments but this explained why and a better alternative thanks a ton

  • @computationaltrinitarianis1451
    @computationaltrinitarianis1451 9 หลายเดือนก่อน

    One use for void* is to attach data to callbacks.
    In Javascript if you write something like:
    const x = 19;
    function foo(y) {
    return x+y;
    }
    function bar(f) {
    console.log(f(23))
    }
    bar(foo);
    Then the value of the function foo at runtime (called a closure) is not only a pointer to the code for foo, but also includes the value of x that it "captures".
    In C, however you can't capture variables in functions the same way. References to functions only refer to the address of the code of the function. So you can do something like
    #include
    int foo(int y, void* x) {
    return *(int*)x + y;
    }
    void bar(int (*f)(int, void*), void* data) {
    printf("%d", f(23, data));
    }
    int main() {
    int x = 19;
    bar(&foo, &x);
    }

  • @lukasmodry196
    @lukasmodry196 9 หลายเดือนก่อน

    iam a programing and software dev student and this is a best video ive seen on void* so far :D. Keep it up man. Thnx

  • @joshuabell6835
    @joshuabell6835 9 หลายเดือนก่อน

    It was great. Your delivery made it great.

  • @dirtdart81
    @dirtdart81 9 หลายเดือนก่อน +1

    Haven't touched C or microcontrollers for a long time, but videos like this get me itching to jump in again. Thanks for a lovely vid!

  • @SolarShado
    @SolarShado 9 หลายเดือนก่อน

    Dude, you're _killing it_ with the jokes in this one. I've lost track now of how many times I've had to pause/rewind because I was laughing and missed something, and I'm only just over halfway through!