What exactly is NULL?

แชร์
ฝัง
  • เผยแพร่เมื่อ 29 พ.ย. 2022
  • Keep exploring at brilliant.org/TheCherno/ Get started for free, and hurry-the first 200 people get 20% off an annual premium subscription.
    Patreon ► / thecherno
    Instagram ► / thecherno
    Twitter ► / thecherno
    Discord ► / discord
    This video is sponsored by Brilliant.

ความคิดเห็น • 612

  • @TheCherno
    @TheCherno  ปีที่แล้ว +105

    Hope you guys enjoyed the video - if you want more C++ videos let me know! Keep exploring at brilliant.org/TheCherno/ Get started for free, and hurry-the first 200 people get 20% off an annual premium subscription.

    • @HermanWillems
      @HermanWillems ปีที่แล้ว

      Why do i never hear you talk about Rust. Are you literally afraid to mention it's name? And why did you never talked about that the inventor of null is ashamed that it exists and that a language should actually NOT have "null". And why don't you just tell us there are languages without null and why they do that and that null should actually not exist?

    • @TheMR-777
      @TheMR-777 ปีที่แล้ว

      @@HermanWillems Calm down mate, calm down...

    • @HermanWillems
      @HermanWillems ปีที่แล้ว +1

      @@TheMR-777 oh i dont mean things personal. Im dutch im quite direct. Sorry if it sounds personal its not. I just had some questions.

    • @TheMR-777
      @TheMR-777 ปีที่แล้ว

      @@HermanWillems Oh alright :)
      It's fine.

    • @pastasawce
      @pastasawce ปีที่แล้ว

      Yes more cpp videos obviously

  • @BM-jy6cb
    @BM-jy6cb ปีที่แล้ว +380

    I'm an old-time hardware/assembly programmer who progressed to C in the late 80's, which I found natural. In the mid 90's, I made a move to C++ and somehow just lost confidence in my ability to understand what was actually going on under the hood. As more and more features were added, I avoided them as "black magic". Your series has rekindled my confidence that it's still just bits and bytes. Thank you!

    • @kayakMike1000
      @kayakMike1000 ปีที่แล้ว +10

      Yeah, compilers and hardware do a lot of heavy lifting and black magic. I have been screwing around with cortex-m stuff, in my cortex-m3, memory address 0 is where the program counter starts and holds the interrupt table address. I think the MCU core is hardwired to that address on a reset, the first IRQ routine is just the reset handler. I think this core has a memory protection unit, so I could set up certain memory locations that cannot be read from by non privileged code... Which triggers an MPU fault, which is handled by the ISR routine...

    • @thefellowbreather
      @thefellowbreather ปีที่แล้ว +3

      C++ does feel a little complex. I would recommend going for Rust. It is in every way a successor.

    • @criostasis
      @criostasis ปีที่แล้ว +2

      If you can’t do, become an expert in what you know and teach.

    • @criostasis
      @criostasis ปีที่แล้ว +1

      Also keep learning!!!

    • @iz5808
      @iz5808 ปีที่แล้ว +1

      @@human-ft3wk as far as I can see for the people who really know what kind of instructions the compiler produces when it comes to arithmetic and memory stuff it is just way too boring and redundant to learn all those 'new' over-the-top features that make programming less fun. Might be wrong but that's my perception

  • @metubr
    @metubr ปีที่แล้ว +199

    I miss the c++ series so much every one is a banger

    • @flflflflflfl
      @flflflflflfl ปีที่แล้ว

      Why do you miss it? It's still there!

    • @elektra81516
      @elektra81516 ปีที่แล้ว +2

      @@flflflflflfl Because he isn't continuing it

    • @flflflflflfl
      @flflflflflfl ปีที่แล้ว +1

      @@elektra81516 do you "miss" half life because there was never a part 3?

    • @benjioffdsv
      @benjioffdsv ปีที่แล้ว +4

      @@flflflflflfl well yes that’s the point

  • @0xDeadC0de1
    @0xDeadC0de1 ปีที่แล้ว +343

    there was a day where compilers didn't care if you used an uninitialized pointer and would just do undefined behavior, made some things really difficult.

    • @aloluk
      @aloluk ปีที่แล้ว +43

      Yep, i was waiting for him to explain what happens when you run it in release mode vs debug without initialising it, but it never happened. I wonder if he even knows being so young.
      For those wanting the answer, in release mode the variable isn't even auto initialised to 0, like it is in debug. So for his example you wouldn't even get an exception reading address 0x8 or 0x20, it will be a random value!!!!

    • @JakobKenda
      @JakobKenda ปีที่แล้ว +29

      GCC still doesn't care. It does give a warning but only if you run it with -Wall. Same with Clang, I guess only MSVC gives an error.

    • @mananasi_ananas
      @mananasi_ananas ปีที่แล้ว +25

      @@aloluk I can't imagine he does not know this. He's been a professional software developer for years at EA.

    • @acuifex
      @acuifex ปีที่แล้ว +4

      @@aloluk 0x20 in release mode is most likely a compile time optimization of std::string. i remember strings having some really wild and weird things like negative offsets, short strings, etc

    • @not_ever
      @not_ever ปีที่แล้ว +2

      @@JakobKenda I can't reproduce this in godbolt using x64 MSVC v19.33. I only get a warning "(14) : warning C4700: uninitialized local variable 'entity' used". Maybe Cherno is using the MSVC equivalent of Werror (whatever that is, I forgot) or some other flag?

  • @olo90
    @olo90 ปีที่แล้ว +24

    12:33 "We don't care about self, at all." That got dark suddenly 🤣

    • @SealedKiller
      @SealedKiller ปีที่แล้ว +1

      We don't care about self at all, this may as well be a static function because we don't even use self.
      Sounds like a life lesson xD
      But there's some truth to that sadly..

  • @uMadBrudi
    @uMadBrudi ปีที่แล้ว +141

    C++ isn't even my main language, but holy moly you learn so much from these deep dive videos it's insane.
    Keep up the amazing video quality Yan

    • @omgwtfafterparty
      @omgwtfafterparty ปีที่แล้ว +1

      yeah, i come from the land of python and i just learnt huge loads of stuff that can help me improve my python classes

    • @TheGreatestWorldFox
      @TheGreatestWorldFox ปีที่แล้ว

      Oh, I'm staying there for a while! Can you recommend any nice places to visit?

    • @FoxSlyme
      @FoxSlyme ปีที่แล้ว +1

      C++ isn't my main language as well, my main one is Russian

    • @RinLovesYou
      @RinLovesYou ปีที่แล้ว

      Understanding pointers is useful in a lot of languages!

  • @jbird4478
    @jbird4478 ปีที่แล้ว +39

    I like how you explain the mechanism instead of just saying "do this and this", what many people on youtube do. Nothing new for me, but people can actually learn from this kind of content, so props to you.

    • @minneelyyyy8923
      @minneelyyyy8923 ปีที่แล้ว +2

      yeah, i really was not expecting this deep of an explanation. while i did already know this it was still good to see.

  • @ycombinator765
    @ycombinator765 ปีที่แล้ว +6

    I swear to GOD that I was havning a conversation about NULL at exercism with a mentor, and came here to YT after having finished asking my question, and here the Cherno is, having upped a video about NULLs and yt recommending it after 3 mins of upload. I feel connected lol

    • @Its.all.goodman
      @Its.all.goodman ปีที่แล้ว

      Things like this happened to me as well

  • @benjaminclehmann
    @benjaminclehmann ปีที่แล้ว +2

    If you want to hear something cursed, C (not sure about C++) compilers are required to give null pointers the value of 0, but their memory representation (like many representations within C) is undefined. This means that setting pointers to 0 and comparing pointers to 0 will work as expected, but only if you do so through a correct type (i.e. T*).
    This means for example, that calloc-ing memory to hold a pointer (or a struct containing pointers) will not necessarily give you null pointers. Same with memset, or any other way of setting the raw bytes of its value. My reading of the spec suggests that using struct foo bar = { 0 } style initializations will give the correct pointer representation.
    This matters generally on some old, kinda funky architectures, often because they were word addressed archs that had sizeof(char*) > sizeof(int*), as they used extra bits to encode an offset within a word. I assume it was helpful to set the leading bits of these addresses to denote that this address was longer than usual. The Tendra compiler lets you set the representation of nullpointers to 0x55555555, as I believe it's a compiler designed for finding obscure platform incompatibilities like this. See www.tendra.org/trans.1/

  • @giantsue
    @giantsue ปีที่แล้ว +36

    Dude seriously after 10 years of working in C++ you keep giving me so much input about stuff I didn't know before. keep going.

    • @jackytaly
      @jackytaly ปีที่แล้ว +3

      you’ve made it 10 years without knowing what null is? props to you

    • @giantsue
      @giantsue ปีที่แล้ว +10

      @@jackytaly that's not what I said :) I liked the part where he explained why member functions that don't access member variables can be called when an instance is null.

    • @jbird4478
      @jbird4478 ปีที่แล้ว +4

      @@giantsue Still though... memory layout is pretty much a core concept that you ought to have learned very early on

    • @giantsue
      @giantsue ปีที่แล้ว +6

      @@jbird4478 happy for you if you did, I didn't.

    • @epolpier
      @epolpier ปีที่แล้ว +3

      @@giantsue It's hard to believe you are 10 years c++ programmer lacking so many basics...

  • @mananasi_ananas
    @mananasi_ananas ปีที่แล้ว +4

    Might be interesting to mention that C++ does not care whether or not you want to access a nullptr. It compiles fine. There is a memory management unit (MMU) in your PC that the OS will configure, usually making the first page of memory inaccessible. This is what makes reading from null an access violation.
    I work in embedded software with C, and before the bootloader configures the MMU, 0 is a valid address. We actually use this area of memory to store data. This is because the bootloader runs on internal CPU memory which is very limited. After initializing the external RAM we use the lowest page to store data which would not fit in the internal RAM. This is fine because the application will never be able to access this data once the MMU is configured correctly.

    • @peepeefrog_
      @peepeefrog_ ปีที่แล้ว

      I would love some insight on that topic;
      But programs run in the os, and live in virtual memory space, not the real memory space. Unlike microcontrollers without os

    • @mananasi_ananas
      @mananasi_ananas ปีที่แล้ว

      @@peepeefrog_ I'm no expert on Windows, but I'd imagine it is the same way. We're not programming bare metal at my job, but we are using a real-time operating system on our microcontroller. Although for us all processes the "virtual memory" will map one-to-one to the physical memory. This allows any process to set GPIO pins with the adresses found in the datasheet for the microcontroller, for example.
      You could also see it as Windows not mapping the first page of virtual memory causing a violation when trying to access address 0.
      Maybe someone with more insight on Windows can chime in with more information.

  • @alecmather
    @alecmather ปีที่แล้ว +10

    Dude I literally love your videos. Even just you showing how you can inspect the physical memory like that?? Never knew that and that's sooo cool.

  • @mladen777
    @mladen777 ปีที่แล้ว +48

    Thanks Cherno for these videos, you’re such an amazing teacher! I hope your C++ series will cover all stuff that is used in C++ programing at some point(if thats eaven possible). It’s already one of the best places for someone to learn C++ (apart from a person coding themselves) and I think it would be amazing for someone to be able to just open your playlist and find anything they need C++ oriented.

  • @andrasvermes
    @andrasvermes ปีที่แล้ว +7

    I was just looking into defining extension methods in C# and found the syntax a bit unusual. Now I totally understand why they are written the way they are. It's kinda like what you explained but in reverse. Really interesting! Thanks :))

  • @ivansirtautas2513
    @ivansirtautas2513 ปีที่แล้ว +2

    I usually get kind of lost in your videos 'cause they a bit advanced for me. But this one was at an epiphany level. So clear and reachable. Thank you

  • @chadbramwell977
    @chadbramwell977 ปีที่แล้ว +2

    Great presentation! I wrote an article a while ago called "how did I crash in that function?" that went through a very similar set of steps that you have here. If you haven't planned it yet, I'd suggest a follow-up for virtual/non-virtual calls and for nested member calls. Also for references since engineers can be easily convinced that a reference somehow protects you from nullptr violations.

  • @Albert-lr7ky
    @Albert-lr7ky ปีที่แล้ว +16

    Great work Cherno! C++videos is a masterpiece, hope you can keep producing it !!!

  • @DTGplays
    @DTGplays ปีที่แล้ว +1

    This series is precisely what they need to teach at Universities. Entertaining, simple but detailed, easy to follow, goes into what (at least my own) University will not go into. I had lost interest in programming due to my crappy Uni course, but thanks to Cherno, I am back and happier than ever to be programming. Thank you so kindly for making this series @The Cherno, I hope to see much more in the future!

  • @andrisszalai1261
    @andrisszalai1261 ปีที่แล้ว +6

    9:21 For the record, that is only true for structs in C. In C++, structs can have functions(=methods) -- even virtual ones --, constructors, public, private and protected members, use inheritance, be templated… just like a class.

    • @master74200
      @master74200 ปีที่แล้ว

      They can in C as well, but it's a bit... Weird.

    • @user-jh4dp6ns4o
      @user-jh4dp6ns4o ปีที่แล้ว

      @@master74200??

    • @master74200
      @master74200 ปีที่แล้ว

      @@user-jh4dp6ns4o Well in C there's no concept of public and private elements as is common in OOP, so that's not a thing in C, but you can have structs that consists of both "member elements" (thats the data you'd normally put in a struct) and also function _pointers_. That means you can allocate a struct with the various data structures you'd usually do, and also have some of the types be pointers to functions. If you look up what a C function pointer looks like (which can also be a parameter to a function), it probably makes more sense.

    • @user-jh4dp6ns4o
      @user-jh4dp6ns4o ปีที่แล้ว

      @@master74200 well you still won't have actual methods this way since function pointers will point to static methods. That means that the function you are calling with obj.fn_pointer() won't have access to obj so can't modify any of its members (unless you explicitly provide obj as one of the function's arguments)

    • @master74200
      @master74200 ปีที่แล้ว

      @@user-jh4dp6ns4o no no, there's a way to do it where you can call the fn ptr on the allocated struct itself and it automatically receives the a pointer to the struct as well. But honestly I don't see the big difference when every part of it is public anyway.

  • @yobonez
    @yobonez ปีที่แล้ว

    This explaination was soo clear, thank you!

  • @billywap
    @billywap ปีที่แล้ว

    Always love these videos!!! Thanks for making another one

  • @avivpk
    @avivpk ปีที่แล้ว +3

    Still the best C++ series out there! Could you please make a video about files in C++ ?

  • @floatoss
    @floatoss 5 หลายเดือนก่อน

    Cherno, you are one amazing human being. Thank you so much for making these videos, they are truly awesome!

  • @kin-dza-dza3929
    @kin-dza-dza3929 ปีที่แล้ว

    Your videos are so helpful. Thank you man.

  • @williamrutherford553
    @williamrutherford553 ปีที่แล้ว

    Love this video, because you never answer JUST the question from the beginning. I never even would've considered that stuff about "offsetof" and when you CAN use a nullptr, but now I do! I think it's SO important in a language like C++ to explain some of the rules, and then ALSO explain all the exceptions to the rule; those exceptions really help you understand the core idea, not a specific problem.

  • @shalip
    @shalip ปีที่แล้ว +1

    WOW, this is one of your best explanations ever. Thanks alot for making me understand it fully :)

  • @gara8142
    @gara8142 ปีที่แล้ว

    This was amazing, thanks for sharing. Knowing deep down how things ACTUALLY work makes a big difference.

  • @alex_8704
    @alex_8704 ปีที่แล้ว +6

    One of the best videos I've seen on C++. I especially liked the part that had covered the implementation of C++ classes in terms of C structs and C functions.

    • @siddharthchauhan1129
      @siddharthchauhan1129 ปีที่แล้ว +1

      Me too… I never thought of it before and now it makes so much sense… like I get it now why python has self keyword.. may be it is interpreted language and can’t have compile time benefit hence they need to put this self keyword

    • @alex_8704
      @alex_8704 ปีที่แล้ว +2

      @@siddharthchauhan1129 I agree. “self” in Python make the distinction between “member” methods and “static” methods more explicit. I mostly use C for math simulations and recently tried to implement somewhat similar to a class for a struct to hold and manipulate a dataframe in C. I mostly struggled to avoid putting this struct into the heap and retaining it in the stack to keep Python-like object.method() syntax instead of object->method() but so far failed

    • @igorthelight
      @igorthelight ปีที่แล้ว +1

      @@alex_8704
      #define -> .
      Would that even work? xD

    • @alex_8704
      @alex_8704 ปีที่แล้ว +1

      @@igorthelight In terms of "#define" my idea was rather to "#define . ->" , but it would have ruined all other dots in my code.

    • @igorthelight
      @igorthelight ปีที่แล้ว +1

      @@alex_8704 True xD

  • @ramonecheverria5856
    @ramonecheverria5856 ปีที่แล้ว

    this is so educational omg the way you connected the dots, great work!!

  • @sir890
    @sir890 ปีที่แล้ว

    great explanation! thanks for the video!

  • @giovannimadrigal3199
    @giovannimadrigal3199 ปีที่แล้ว +3

    Thank you! I'm new to C++ and this series has been super helpful. If I may suggest an idea, could you make a video on how to read data from a gzipped file line by line regardless of how long the lines are?

    • @peepeefrog_
      @peepeefrog_ ปีที่แล้ว

      Read about «stream»

  • @Byynx
    @Byynx ปีที่แล้ว +1

    Priceless explanation!!!

  • @veerbhadra7332
    @veerbhadra7332 ปีที่แล้ว +1

    Hello Cherno,
    I really like the way you teach. Could you please make a tutorial on design patterns

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

    Awesome , simple explanation!

  • @aaronwinter7911
    @aaronwinter7911 ปีที่แล้ว +18

    My guess about 0x8: It just assumes that the entity value is at address 0x0. The first 8 bytes of Entity (0x0 through 0x7) are the pointer to the parent entity.
    For C++ 0x0 is a valid memory address, so it happily returns that bit in the heap, but since we are calling ->GetName() we are actually trying to access the `string m_Name`, which starts at 0x8, since the first 8 bytes of an Entity is the parent pointer.

    • @ZeroUm_
      @ZeroUm_ ปีที่แล้ว +12

      I'd just correct the part you said it "assumed" the entity was at 0x0.
      The code explicitly set the object address to 0x0, no guesses were made.

  • @yillin
    @yillin ปีที่แล้ว

    This was a great video. I am, for the most part, self taught when it comes to c++ programming. That is to say, I've been through books and tutorials but my knowledge of real world application is zero. However, Cherno's videos are still enlightening and very interesting to watch, even if I will never find myself applying this outside of a hobbiest's interest. Thanks for the video.

  • @gamesucht2097
    @gamesucht2097 ปีที่แล้ว

    thankyou. that gived me a new understanding of C++ and compiled programming languages and how they work

  • @GamingDemiurge
    @GamingDemiurge ปีที่แล้ว

    Best explanation of null I've ever seen. Your videos are clear and on point. Love it.

    • @HermanWillems
      @HermanWillems ปีที่แล้ว

      He did not explain why NULL is literally a mistake in languages who have it. And that NULL has costed billions and billions of dollars. There is a clear reason why Rust for example has no NULL. Even the inventor of NULL is ashamed for it and said it is his biggest mistake and said it should not exist. Null should not exist.

  • @kraiw0
    @kraiw0 ปีที่แล้ว

    this was such a good video :) ran into this just two days ago, thanks for the explanation

  • @zdspider6778
    @zdspider6778 ปีที่แล้ว

    This was an important video and I think you nailed it. Well done.

  • @mikefochtman7164
    @mikefochtman7164 ปีที่แล้ว +1

    Great explanation. Used to argue with a coworker that NULL COULD in theory be defined as so long as it was sure to be a read access violation. 0x00 just happens to be a read violation on all platforms. But a lot of legacy code/ systems would break because many times it would simply be tested against the integer zero. I know that was quick and easy, but seems like it was mixing data types in a messy way. I always preferred to use NULL or nullptr as it keeps the proper abstraction concepts. Not so 'implementation specific'.
    Like using an integer value for a Boolean. If you change some details of implementation, you probably will break things. But if you stick with proper typing, much safer.

  • @c2ashman
    @c2ashman ปีที่แล้ว

    Amazing content. Great stuff.

  • @danielnavarrete8571
    @danielnavarrete8571 ปีที่แล้ว

    Great in-depth explanation!

  • @duminduakalanka9340
    @duminduakalanka9340 18 วันที่ผ่านมา

    I was watching the original Cpp videos from 6 years ago and suddenly stumbled on to this video. Wooohhh, Dude has changed so much😀. I love it.

  • @yosefshawah3019
    @yosefshawah3019 ปีที่แล้ว

    Absolute legend mate! Thanks

  • @tbmj
    @tbmj ปีที่แล้ว +1

    You absolute legend, you just saved a project I’ve had on the to-do list

  • @stupidm
    @stupidm ปีที่แล้ว

    nice explaination!

  • @louiscresswell5436
    @louiscresswell5436 ปีที่แล้ว

    clicked on this video to get the answer that was explained in the first minute or so. So glad I stayed, very interesting. The funny thing is I don't see how this knowledge is going to help me with my work but I'm still glad to know it. Hope you do more videos like this. The information was very concise and well explained :)

    • @PedroOliveira-sl6nw
      @PedroOliveira-sl6nw ปีที่แล้ว

      I don't know if it can help with your work but one thing this knowledge can give you is how to hack into classes. Suppose that you are given a class A { private: int value; }; and you can reinterpret_cast it to class A_hacked { private: int value; public: int get_value() { return value; } }; which you can use to get the value.

  • @andrez383
    @andrez383 ปีที่แล้ว

    Hi Cherno awesome video! Please keep on making C++ videos. They are the best ones outthere.
    Also your Walnut video and repository is gold for unexperienced hobby programmers like me. If you would ever show how to port an app built on your Walnut framework to Mac that would make me veery happy :)
    have a good one... cheers

  • @boredbud2997
    @boredbud2997 ปีที่แล้ว

    i didn't understand much of what you said cause I don't know much and also cause I'm missing a lot of sleep, but I definitely need to watch more of your videos

  • @eplusplus
    @eplusplus ปีที่แล้ว +1

    Interresting! What font are you using? It looks clean

  • @imereque
    @imereque ปีที่แล้ว

    Hi Cherno!
    It's amazing how much depth there is in the humble zero!
    Would you consider making a video on variadic templates or custom allocators?

    • @deang5622
      @deang5622 ปีที่แล้ว

      It usually isn't zero, it's more likely to be:0xFFFFF...
      As many F's as there are in a memory address...

  • @milasudril
    @milasudril ปีที่แล้ว +1

    If gcc can infer that you will dereference a nullptr, it sometimes replaces the actual memory de-reference by an ud2 instruction, which is a clever way of crashing (no triggering of pagefaults, and no involvement of syscalls). This results in a SIGILL instead.

  • @hectormejia499
    @hectormejia499 ปีที่แล้ว +2

    holy crap this is awesome, you just became one of my favorite programming youtubers

  • @pnuema1.618
    @pnuema1.618 ปีที่แล้ว

    This video is gold in the context of understanding "this". Thanks!

  • @absolute_zero982
    @absolute_zero982 ปีที่แล้ว

    this video make my day bro ty

  • @Karlemilstorm
    @Karlemilstorm ปีที่แล้ว

    I learned quite a bit from this. Thank you!

  • @bunpasi
    @bunpasi ปีที่แล้ว +2

    Interesting video. Never thought about the effects of calling a method of an uninitialized variable.
    2 notes for viewers.
    - Always initialize your raw type variables like int, float, pointers, etc. Only as members of classes its done for you.
    - Using uninitialized data is undefined and will not throw an error in release mode. This is one of the most occurring bugs, since you might never find out about it.

  • @randomgeocacher
    @randomgeocacher ปีที่แล้ว +2

    An addition; C/C++ code halting on null pointer dereference should be considered implementation specific. You could memory map 0/null to your process if you are insane, and not all non-memory managed architectures crash on access to 0/null.

  • @greob
    @greob ปีที่แล้ว

    Interesting, thanks for sharing!

  • @s1nister688
    @s1nister688 ปีที่แล้ว

    This is some amazing stuff. Thanks for making a video on it.

  • @miguelguthridge
    @miguelguthridge ปีที่แล้ว +5

    This is genuinely super interesting and gives lots of insights into how C++ works under the hood

  • @Basel-ll8fj
    @Basel-ll8fj ปีที่แล้ว +1

    This was really deep, before I saw the video I thought I knew what null really is and just watched it for fun,
    good job Cherno 👌👌

  • @smarttrupti2007
    @smarttrupti2007 ปีที่แล้ว

    Wow, Amazing session👍

  • @idkkdi8620
    @idkkdi8620 ปีที่แล้ว

    Wow, this was awesome! Thanks!

  • @MultiKaloudis
    @MultiKaloudis ปีที่แล้ว

    This is amazing! How much time did you need to have complete picture about nullptr?

  • @DeathStar95
    @DeathStar95 ปีที่แล้ว

    beautifully explained!

  • @themyuul6559
    @themyuul6559 ปีที่แล้ว

    fantastic video, cheers

  • @stephenreaves3205
    @stephenreaves3205 ปีที่แล้ว

    Super helpful video. You also inadvertently explained why rust methods take in 'self' as the first parameter. Turns out C++ had been doing it for years and just never told you

  • @ErrorJan
    @ErrorJan ปีที่แล้ว

    16:45 THIS MAKES SOO MUCH SENSE! Wow. I love C++

  • @lorincmate
    @lorincmate ปีที่แล้ว +3

    As an Embedded C dev, this episode helped me a lot to understand C++. Thank you

    • @mindblower113
      @mindblower113 ปีที่แล้ว

      Sorry but how much do you earn monthly?

  • @roelvanhout5449
    @roelvanhout5449 ปีที่แล้ว +1

    Now to complete this, do virtual functions and how vtables fit into memory layout of objects. . And how the pack pragma affects these values in msvc.

  • @siddharthchauhan1129
    @siddharthchauhan1129 ปีที่แล้ว

    I kid you not.. after I learn things from you.. I sure sound really smart in front of my colleagues.. your explanations are so precise and cover very critical points..

  • @mbehboodian
    @mbehboodian ปีที่แล้ว

    Man... I literally missed you. The last videos I saw from your channel were OpenGL series from 5 years ago! I'm not sure how YT suggested a video while I wasn't subscribing, but man, you got older :)
    Keep it up my friend...

  • @sanctuary_of_soul
    @sanctuary_of_soul ปีที่แล้ว

    Very very cool! Thanks

  • @avdhendrasingh9994
    @avdhendrasingh9994 ปีที่แล้ว

    these kind of video will keep my foundation even more strong

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

    this is one of the best yt videos i've ever seen

  • @VictorMistral
    @VictorMistral ปีที่แล้ว +2

    NULL is not nullptr, one is a int with the value of 0, the other is a ptr to the zeroth position in memory.
    It makes a important distinction for some fct overloading handling since the type is not the same!

    • @user-cy1rm5vb7i
      @user-cy1rm5vb7i ปีที่แล้ว

      nullptr is not a pointer tho 😏 It is an object that can be casted to a pointer of any pointer type, and the value of that pointer would be 0. And on some systems, NULL is also a pointer, and not a number, probably a void* or some compiller intrinsic value, that is treated as a memory address

  • @Ghost-Snow-Rabbit
    @Ghost-Snow-Rabbit 6 หลายเดือนก่อน

    Thank you, it's so good to know how it works.

  • @enesk2120
    @enesk2120 ปีที่แล้ว

    bro, this was just awesome

  • @MutantOpa
    @MutantOpa ปีที่แล้ว

    I'm always surprised how helpfull C++ and C code is when thinking about assembler and reverse engineering. Thank you | good video :)

  • @xsandre-l
    @xsandre-l 9 หลายเดือนก่อน

    Any chance we can get a video on cpp modules? that would make my year thanks😄

  • @thecloudterminal
    @thecloudterminal ปีที่แล้ว

    Great video. Thank you for sharing

  • @pejsh726
    @pejsh726 ปีที่แล้ว

    What a great video... and I don't even work with C++, still really great and interesting. Thanks.

  • @embeddedbastler6406
    @embeddedbastler6406 ปีที่แล้ว +2

    The standard does not specify that nullptr has to refer to the address 0. It only says that the literal value of 0, in a pointer context, must be interpreted by the compiler as nullptr.
    Therefore 0 *can* be a valid memory address.

  • @freezinfire
    @freezinfire ปีที่แล้ว

    Not only null, but my concepts of structs, classes and memory address allocation were all cleared. Thank you.

  • @debreky8709
    @debreky8709 ปีที่แล้ว

    Brilliant video!

  • @htmCode
    @htmCode ปีที่แล้ว +2

    i can't imagine that i actually have an java exam tomorrow and i'm here watching this c++ video because of how great it is

    • @snlagr
      @snlagr ปีที่แล้ว

      how was the exam bro?

  • @skeleton_craftGaming
    @skeleton_craftGaming ปีที่แล้ว

    There's a physical address zero but it is always reserved by the operating system, and also the operating system most likely nowadays doesn't allow you to use direct addressing anyway, so the virtual address tables that the OS uses probably doesn't have a zero entry.

  • @minneelyyyy8923
    @minneelyyyy8923 ปีที่แล้ว +5

    It would be really cool to see you cover virtual memory. covering how the operating system actually loads your code, how it manages your memory, and stuff like that could be so cool. you seem to have an above average understanding of these low level topics, which is why I am bringing it up. virtual memory is a very very VERY important concept in modern operating systems and a video about it could contain some useful information for programmers.

    • @piechulla1966
      @piechulla1966 ปีที่แล้ว

      If your application really gets into this situation, you should rather buy additional main memory.

    • @tablettablete186
      @tablettablete186 ปีที่แล้ว

      @@piechulla1966 What? Virtual memory is not just important to use with paging, it is also useful to isolate processes.

    • @piechulla1966
      @piechulla1966 ปีที่แล้ว +1

      @@tablettablete186 The definition(s) of "virtual memory" are not entirely clear to me now. Cherno should perhaps really take on the topic 🙂

    • @tablettablete186
      @tablettablete186 ปีที่แล้ว

      @@piechulla1966 Agree, but perhaps I can help a bit.
      Virtual memory is nothing more than an abstraction over the physical address of memory.
      So, the process can only access virtual addresses and they are translated on the fly by the hardware when being in use.
      In another way, a process will read address 1000 and the hardware will map it to a physical address (let's say 3888) and return its value.
      This helps in 2 things:
      1. Isolation: map different physical addresses to different processes, and they all see (0 to 2^64)
      2. Paging: you can use use this abstraction to map virtual addresses to your SSD
      Source: Tannenbaum's book Modern Operating Systems (or something similar)

    • @piechulla1966
      @piechulla1966 ปีที่แล้ว +1

      @@tablettablete186 When does this come into play? Say I do:
      m_pSomething = new int[nNumOfNeededSomethingSlots]; // Nevermind C26409: Avoid calling new and delete explicitly, use std::make_unique instead (r.11).
      or
      std::vector vLfSomething;
      // ..
      vLfSomething.push_back(lfSomeValue);
      Usually I do not care what goes on behind the scenes. As long as I don't have to worry about it actually being swapped to disk (performance decline with a factor 10,000 or so for an HDD, not sure about SSDs).
      Seems to me that swapping to disk was interesting in the 1980ies (back then memory was very expensive) and is no longer important nowadays. Also, looks like it is turned off by default in Win 10, Win 10 IOT, and Win 11.
      Isn't the address space that a process is assigned by the operating system always "virtual" anyway?
      So many questions. I know that I know nothing. Which I mostly do not care :-)

  • @aspidinton
    @aspidinton ปีที่แล้ว

    Congrats with 500k

  • @zxnnightstalker2289
    @zxnnightstalker2289 ปีที่แล้ว

    wow, that's really deep but how to know that's kind of detail, let me know the resource that you get from. You are really amazing.

  • @charlesmuzhanye4144
    @charlesmuzhanye4144 ปีที่แล้ว

    Wish I could double like this, great content

  • @danielaviv8215
    @danielaviv8215 ปีที่แล้ว +3

    Amazing as always!
    can you please do a video about c++ writing conventions, it would be very helpful!

  • @MrSasYo
    @MrSasYo ปีที่แล้ว

    Great video!

  • @RequiDev
    @RequiDev ปีที่แล้ว +2

    Could've used Godbolts Compiler Explorer to showcase what actually happens under the hood as well.

  • @jaime7295
    @jaime7295 ปีที่แล้ว

    These videos talking about general c++ concepts are really interesting

  • @karwannouri8266
    @karwannouri8266 ปีที่แล้ว

    Great video, thanks.
    Why would it be better to init the object on the stack instead of on the heap?

  • @444limm
    @444limm ปีที่แล้ว +2

    I really like c++ series on this channel

  • @stdDizzasTeR
    @stdDizzasTeR ปีที่แล้ว

    Nobody teaches this stuff and I'm always caught off with such knowledge Cherno!