Why Is C SO Dangerous?

Поділитися
Вставка
  • Опубліковано 23 вер 2024
  • Live on Twitch: / lowlevellearning
    🏫 COURSES 🏫 Check out my new courses at lowlevel.academy
    🙌 SUPPORT THE CHANNEL 🙌 Become a Low Level Associate and support the channel at / lowlevellearning
    Why Do Header Files Exist? • why do header files ev...
    How Does Return Work? • do you know how "retur...
    🔥🔥🔥 SOCIALS 🔥🔥🔥
    Low Level Merch!: lowlevel.store/
    Follow me on Twitter: / lowleveltweets
    Join me on Discord!: / discord

КОМЕНТАРІ • 2,5 тис.

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

    live on twitch! twitch.tv/lowlevellearning

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

      when you code in c i feel like you're going back -50 years, just use js, be simple, but powerful, man, just be simple, you know, life is kinda short

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

      C isn't unsafe. Kernighan and Richie said "You better know what you are doing".
      It's the Programmer who pulls the Trigger.

    • @usamaismail-u9r
      @usamaismail-u9r Місяць тому

      Which keyboard are you using?

  • @SigSeg-V
    @SigSeg-V 6 місяців тому +20178

    What a glorious bait. A true master baiter

  • @astral6749
    @astral6749 6 місяців тому +14354

    I thought I clicked on the wrong video

    • @Kane0123
      @Kane0123 6 місяців тому +62

      You’re opening up a bit much if that video was on your home / subscription page my man 🤣

    • @astral6749
      @astral6749 6 місяців тому +666

      @@Kane0123 Nah. The title and thumbnail are both programming related, hence why I clicked it. But then some random woman appeared so I thought I misclicked.

    • @mustafa_el-rashied
      @mustafa_el-rashied 6 місяців тому +30

      me too

    • @alixcozmo
      @alixcozmo 6 місяців тому +17

      Me too lmao

    • @cinderwolf32
      @cinderwolf32 6 місяців тому +80

      ​@@astral6749 Same. I saw the title and thumbnail and wanted to see what pointer/array issue he showed. I almost hit the back button when the first clip started, since I thought I had gone to the wrong short, but it was onto the code quick enough

  • @jacob416
    @jacob416 6 місяців тому +6075

    Basically:
    It’s unsafe because it will do exactly what you tell it to do, which isn’t always a good thing.

    • @shringe9769
      @shringe9769 6 місяців тому +188

      That would be fine; if it could to tell your 3 lines of static code was gonna fail at compile time.

    • @nmrocks28
      @nmrocks28 5 місяців тому

      ​@@shringe9769clang can warn about pretty much any compile time or possible runtime errors while compiling. GCC would probably also give a warning with some warning options enabled

    • @yowza9638
      @yowza9638 5 місяців тому +94

      This is just programming in general

    • @RR-et6zp
      @RR-et6zp 5 місяців тому +2

      they date up

    • @RR-et6zp
      @RR-et6zp 5 місяців тому +2

      @@shringe9769 they date up

  • @brutusthebuttress1476
    @brutusthebuttress1476 4 місяці тому +3156

    C is unsafe the same way a motorcycle is unsafe

    • @segueoyuri
      @segueoyuri 4 місяці тому +150

      thing about motorcycles is that gravity always wins. You'll fall at some point lol

    • @somersaultinggiraffe1901
      @somersaultinggiraffe1901 3 місяці тому +396

      @@segueoyuri skill issue tbh.

    • @segueoyuri
      @segueoyuri 3 місяці тому +53

      @@somersaultinggiraffe1901 you're very right nonetheless hahahah

    • @FrankHarwald
      @FrankHarwald 3 місяці тому +12

      it's worse then a proper motorcycle.

    • @justarandomguy6794
      @justarandomguy6794 3 місяці тому +38

      @@segueoyuri 3 years, 24000Kms and not a single crash/bump

  • @grogu9814
    @grogu9814 4 місяці тому +777

    When I first learned C in college this was like the first thing the professor taught us lol

    • @luiggitello8546
      @luiggitello8546 3 місяці тому +38

      I go excessively nuts on the input validation just in case

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

      @@luiggitello8546 crowdstrike should have hired you lol

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

      @@grogu9814 I will go to University, and our University too teach us to C++ for first year......

  • @marh122
    @marh122 6 місяців тому +4463

    the fastest "No thank you" rofl

    • @kralekis
      @kralekis 6 місяців тому +12

      Rotfl sounds better

    • @maxave7448
      @maxave7448 6 місяців тому +110

      Her: "Do you want to make a girl like you?"
      Him: "No thank you. So the reason C is an unsafe language ..." 🗿

    • @JapesZX-streams
      @JapesZX-streams 6 місяців тому +6

      My man doing some Aaron Paulsen shit hahah

    • @devops-sushi5534
      @devops-sushi5534 6 місяців тому +1

      faster then light

    • @aetherland1883
      @aetherland1883 5 місяців тому +13

      we are tired of their lies

  • @akulkis
    @akulkis 6 місяців тому +2754

    "C allows you to do dangerous things so that you can do interesting things." -- Brian Kernighan

    • @yjc5931
      @yjc5931 5 місяців тому +24

      This is so true

    • @rickrock2525
      @rickrock2525 4 місяці тому +56

      "C allows you to do dangerous things" because Brian Kernighan didn't know how to prevent these things without paying a (high) price.
      2015 rust came out.

    • @baranosiu
      @baranosiu 4 місяці тому

      @@rickrock2525 C was created as a system programming language. It was supposed to give the programmer capabilities and performance similar to assembler, while ensuring easy transfer of code between different machines. The language was supposed to allow the programmer to do everything so that there was no need to use assembler for system programming, including free access to memory, hardware registers, etc. (the programmer was supposed to know what he was doing, the language was not supposed to limit him in any way). Thanks to this, even today C works great when programming microcontrollers or embedded systems, even those with only a few kilobytes of memory.
      If there is a need to control out-of-bounds, etc., you can always encapsulate access to the resource using your own functions (or use libraries created for this purpose).
      Rust is great in concept, but in practice it requires access to the source code of all libraries used if you want to fully use 'safe mode' (apart from the fact that even the standard Rust library uses 'unsafe' code, but that may change in the future ) - this is supposed to provide zero-cost for all security mechanisms, but nevertheless, for example with the above-mentioned tables, there is an overhead of checking ranges while the program is running. Rust can replace C (and some other languages) in many contexts, but it is not a complete replacement for it.

    • @joshuajamesweiss
      @joshuajamesweiss 4 місяці тому

      ​@@rickrock2525 I am also a rustacean but I wish other programmers would stop sucking off the crab like it was sent by God.

    • @StratOCE
      @StratOCE 4 місяці тому +44

      @@rickrock2525 I *love* Rust, BUT it isn't the solution to all of life's problems. Rust still doesn't run on some of the platforms you can run C on, moreover, the safety of Rust comes with a cost not in performance but in human time. Yeah, it's true, a refactor on a Rust codebase will usually be faster than on a C codebase, but experimental code in Rust can be a real pain in the behind. And no, unsafe isn't the solution to that problem.

  • @kumanderlinux
    @kumanderlinux 5 місяців тому +904

    "No, thank you! Now..." LMAO!! XD

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

      @@kumanderlinux now THAT'S the guy worth dating! Love him!

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

    "C has no way to check it"
    It actually has, but you have to code it yourself. People take others works for granted and that is crazy.

  • @LydellAaron
    @LydellAaron 4 місяці тому +374

    Didn't expect that intro. C is/was designed for people who want to directly control a hardware processor and an operating system. It's perfect.

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

      Mapping bit fields to hardware addresses in the linker and directly twiddling bits is beautiful

    • @mr.xdstrem1584
      @mr.xdstrem1584 Місяць тому +4

      the biggest lie is strings :(

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

      ​@@mr.xdstrem1584 Especially when utf-8 is involved.

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

      @@mr.xdstrem1584 lol yeah more like a character array

  • @MA-748
    @MA-748 5 місяців тому +270

    Seriously thought UA-cam was malfunctioning when I clicked this video

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

      same lmaooooo

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

      It does malfunction this way sometimes fr

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

      fr

  • @whoeverofhowevermany
    @whoeverofhowevermany 6 місяців тому +785

    😂 I swiped away just as you said no thank you and so I came back 😂

    • @justsomeone953
      @justsomeone953 5 місяців тому +17

      you are fast :D

    • @AxissXs
      @AxissXs 5 місяців тому +5

      Exactly 😂😂😂

    • @victoryemmanuel642
      @victoryemmanuel642 4 місяці тому +6

      Same thing 😂

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

      Same

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

      Ah, yes, our attention spans are of this length, at least we code instead of rotting away entirely on short form videos…

  • @chunkyg6715
    @chunkyg6715 5 місяців тому +80

    I see the problem here. The programmer was distracted by the girl and forgot to validate user input. 😂

  • @HD_Heresy
    @HD_Heresy Місяць тому +61

    That opening absolutely sent me "no thank you now the reason C is so dangerous" just doesn't miss a beat 😂

  • @Henry14arsenal2007
    @Henry14arsenal2007 5 місяців тому +12

    C has a way of checking. Its an if statement after receiving an input and its called input validation. Now, its the other, memory-safe languages that dont have a way to NOT check it in case you dont need it and hogging that compile/run time.

  • @onenationunderdog5289
    @onenationunderdog5289 6 місяців тому +274

    That bait and switch had me click off and then quickly back up "wait what that short was actually about C memory issues let me finish that"

    • @bgdgdgdf4488
      @bgdgdgdf4488 5 місяців тому +11

      C doesn't have memory issues, bad programmers do

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

      @@onenationunderdog5289 yes, we only need compilers to like us.

  • @peterzstudio
    @peterzstudio 5 місяців тому +241

    The polite "um no thank you" got me rolling on the floor

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

      That must have looked so stupid when you did….

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

      That was also the most developerish response possible. Make girls like me ? No, thank you. I'd rather learn about C.

  • @kuhluhOG
    @kuhluhOG 6 місяців тому +1645

    "The integer array has 4096 Bytes allocated to it."
    While it doesn't impact the rest of the video, this sentence has one big mistake.
    The array has 4096 elements. Since it's an int array and most (Desktop) platforms have 4 Byte integers, this array is 16384 Bytes big.
    Also, literally needed to change the URL from shorts to watch since on the "shorts" interface the "Comment" button was unreachable after typing this.

    • @cybernit3
      @cybernit3 6 місяців тому +54

      Exactly, he made a mistake... since int will take 2 bytes or even 4 bytes (long int) per array element. But I get his point.... I find C easier to read.... object oriented languages like C++ make it harder to read and understand for myself.

    • @kuhluhOG
      @kuhluhOG 6 місяців тому +109

      @@cybernit3"since int will take 2 bytes or even 4 bytes (long int) per array element"
      long int has nothing to do with this here
      also, on Windows, macOS and Linux 64bit, if you just use "int", it will be 4 Bytes
      "I find C easier to read.... object oriented languages like C++ make it harder to read and understand for myself"
      Ok, but this has nothing to do with anything here.

    • @johnalberto9600
      @johnalberto9600 6 місяців тому +30

      It very much depends on where are you programming. In embedded systems is usual that int are 2 bytes size

    • @kuhluhOG
      @kuhluhOG 6 місяців тому

      @@johnalberto9600yes, that's why I said "on most (Desktop) platforms"
      and even with 2 Bytes it's still way more than 4096 Bytes

    • @whoami5327
      @whoami5327 6 місяців тому +9

      I was searching for this comment 😂🎉

  • @jacktheproslegend
    @jacktheproslegend Місяць тому +10

    Coding languages that follow everything you say literally and without any questions can indeed be very dangerous when you have no idea wtf are you doing

  • @zhamkaxel4854
    @zhamkaxel4854 5 місяців тому +44

    This is why vectors and templates exist in C++

    • @wile9763
      @wile9763 3 місяці тому +8

      C++ doesn't protect you when using the index operator. You will have the same problem. However, std::vector does have an at method which will throw an error if the index is out of bounds. In my experience it is rarely used, though.

    • @LARAUJO_0
      @LARAUJO_0 3 місяці тому +9

      The amount of times I've ran into the "vector subscript out of range" pop up has something to say about that

    • @jameskingcodes
      @jameskingcodes 3 місяці тому

      @@wile9763 rust doesnt protect out of bounds indexing either.

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

      @@wile9763I don’t use at method because I like [i] more.

  • @chookingvid
    @chookingvid 6 місяців тому +772

    I already knew this about C, but I still don't know how to make a girl like me.

    • @solidacid1337
      @solidacid1337 6 місяців тому +279

      The first part of your sentence is the reason for the second.

    • @chrikke
      @chrikke 6 місяців тому

      Explain C to them. If they don't like that, then get on your knees and beg them to like you

    • @electrolyteorb
      @electrolyteorb 6 місяців тому

      ​@@solidacid1337now that's genius

    • @smallcube-zn2mm
      @smallcube-zn2mm 6 місяців тому +64

      Your hard earned money through C programming skill will make girls follow you

    • @cherubin7th
      @cherubin7th 6 місяців тому +65

      Live dangerous like coding in c

  • @pseudo.Random-KF
    @pseudo.Random-KF 5 місяців тому +35

    I scrolled off right before he said "no thank you".
    Then I scrolled back in.

  • @noddle045
    @noddle045 6 місяців тому +361

    It doesn’t allocate 4096 bytes it allocates 4096 * sizeof(int) bytes

    • @balancemyself
      @balancemyself 6 місяців тому +4

      Yes that is the count of elements.

    • @sethkills
      @sethkills 6 місяців тому +2

      What if sizeof(int) is 3, with an address alignment of 5 bytes?

    • @Alfred-Neuman
      @Alfred-Neuman 6 місяців тому +2

      @@sethkills yes

    • @noddle045
      @noddle045 6 місяців тому

      @@sethkills would it allocate 4096 * 5 bytes?

    • @jhgvvetyjj6589
      @jhgvvetyjj6589 6 місяців тому +3

      @@sethkills The result of sizeof will be a multiple of the alignment of the type. Like how the 80-bit extended precision of x87 may be 10 byte long double on some compilers but 12 byte or 16 byte on some compilers due to alignment padding.

  • @chashmal10
    @chashmal10 Місяць тому +29

    “C is unsafe”
    “What if we allow any user to select arbitrary memory over the internet”
    Which part is unsafe? Lmao

  • @Lloyd_Brown
    @Lloyd_Brown 5 місяців тому +27

    One of the finest video introductions I have witnessed. Thank you sir.

  • @Kane0123
    @Kane0123 6 місяців тому +330

    You owe me an A4 notebook for making me spit coffee all over my desk in laughter.

    • @gerooq
      @gerooq 6 місяців тому +4

      unoriginal, cringe and lame

    • @hellwraiz
      @hellwraiz 6 місяців тому +50

      ​@@gerooqunoriginal, cringe and lame

    • @gerooq
      @gerooq 6 місяців тому

      really proved your point there by copying my comment@@hellwraiz

    • @pikachuisop123beee9
      @pikachuisop123beee9 6 місяців тому +11

      @@gerooqyou just got uno reversed Lbozo Also ratio^^^

    • @-Cocell
      @-Cocell 4 місяці тому +1

      ​@@pikachuisop123beee9These kids. :

  • @aeebeecee3737
    @aeebeecee3737 6 місяців тому +386

    RUST: Memory safety
    C: ha ha lol 😂

    • @lockaltube
      @lockaltube 5 місяців тому +50

      RUST: Memory safety
      C: no thank you

    • @hherpdderp
      @hherpdderp 5 місяців тому +83

      Can I use this memory?
      C: Sure
      Rust :🔫🤣 no
      Java: one for you , three for me.
      Python: Hold on let me ask C.

    • @DynamicalisBlue
      @DynamicalisBlue 5 місяців тому +17

      C++: has everyone forgotten about me?

    • @danielkik1245
      @danielkik1245 5 місяців тому +16

      @@hherpdderp Rust has like 300 memory based exploits too lmao

    • @kaiseheretic7847
      @kaiseheretic7847 5 місяців тому +6

      ​@@danielkik1245That doesn't change the fact that c is worse in memory safety.

  • @raymaleh8851
    @raymaleh8851 6 місяців тому +27

    This is the hardest I laughed all week. Brilliant start to the video!

  • @user-vr2rq5hl6l
    @user-vr2rq5hl6l Місяць тому +4

    C has been perfect for my work over the past 30 years. C can be as efficient as assembly code. If C had “guardrails”, then it would lose its efficiency.

  • @Lord-Of-Light
    @Lord-Of-Light 5 місяців тому +60

    This is a wise man to run from their traps.

  • @xXJM01Xx
    @xXJM01Xx 5 місяців тому +117

    That "No thank you" at the start... I really vibe with that

  • @4I3X
    @4I3X 5 місяців тому +13

    "I Came Looking For Copper And I Found Gold"

  • @nepeta3286
    @nepeta3286 6 місяців тому +15

    "no checks" yes there are, you need to enable all warnings (-Wall), you can even go further and force it into errors (-Werror), there's also sanitizers and debuggers for that purpose

    • @annieannamoore6011
      @annieannamoore6011 3 місяці тому

      I also thought about -Wall but does it check for array index out of bounds? I'm not sure.. also, it is always a good idea to know how to write a safe code without counting on other tools to save your ass 😂

    • @nepeta3286
      @nepeta3286 3 місяці тому +1

      @@annieannamoore6011 of course it is! never denied it was important to learn how to write safe code, just argued that LLL's claim about C's safety isn't really accurate ^^'
      i do agree that devs should learn how to write safe C though ofc

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

    if (i < sizeof(array) / sizeof(array[0])). Ideally store that value instead of calculating every time. That's basically how every proper programming language works dude. You being "allowed" to write code that is unsafe doesn't make the language unsafe.

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

    The C and C++ languages are free as in speech. Freedom is power. Freedom is also viewed by the weak as dangerous. The only thing more dangerous is not having it.

  • @SeRoShadow
    @SeRoShadow 6 місяців тому +120

    Un-validated inputs into unsafe operations usually result in this since the compiler or the interpreter didnt account for that. So the Dev must do it instead.

    • @gagagero
      @gagagero 6 місяців тому +16

      Yeah, language doesn't really prevent this. Checked access does.

    • @raffimolero64
      @raffimolero64 6 місяців тому +2

      ​@gagagero by checked access does the program have to do something meaningful on bad access or is reliably crashing good enough
      can't hack if the program always shuts down on bad input

    • @sansmojo
      @sansmojo 6 місяців тому +7

      ​@raffimolero64 There's no simple answer to this. It really depends on what the program is doing. Crashes can and have been exploited for RCE (remote code execution). If your program is a web service then, at best, you've made your service unreliable and, at worst, given someone an extremely easy way to DOS you. If your program is flight control software, then you've potentially provided a way to bring your aircraft down. If your program is a calculator, then maybe there's no harm aside from unreliability. In general, though, the best advice I can give is that crashing your program is rarely something that you want to let happen, even if there's no malicious intent.

    • @sethkills
      @sethkills 6 місяців тому

      What’s the interpreter, the machine?

    • @markoates9057
      @markoates9057 5 місяців тому +8

      100%. This problem has nothing to do with C, just bad programming. Always validate your inputs from outside the system. whadahek.

  • @sa-hq8jk
    @sa-hq8jk 6 місяців тому +71

    bro pulled a rainbolt

    • @rohitchaoji
      @rohitchaoji 6 місяців тому +6

      But did he locate the error in 0.1 second while looking at the grass?

    • @rayjynx
      @rayjynx 6 місяців тому +3

      an ezsnippet, if you will

    • @yanmorin1503
      @yanmorin1503 6 місяців тому

      nice

    • @arivald6677
      @arivald6677 6 місяців тому

      Gothamchess also started to copy this entrance.

  • @satishkumar1221
    @satishkumar1221 6 місяців тому +188

    That’s why we have to do static code analysis

    • @captainfordo1
      @captainfordo1 6 місяців тому +6

      Not really

    • @mikopiko
      @mikopiko 6 місяців тому +2

      @@captainfordo1Why do we have static code analysis? Isn't for catching these issues to some extent?

    • @m4rt_
      @m4rt_ 6 місяців тому +28

      @@mikopiko if the index is hard coded somewhere and will be used at some point on the array then it might be a thing it could catch, but if it takes in data that can't be determined at compile time, e.g. from a text prompt, a random number generator, or a request over the internet, then it won't be as easy.

    • @mikopiko
      @mikopiko 6 місяців тому

      ​@@m4rt_I understand that, but I was wondering what @captainfordo1 meant?

    • @narrativeless404
      @narrativeless404 6 місяців тому +1

      ​​@@m4rt_ Eh, would be cool to have dynamic code analysis
      Imagine how much easier would it be to deal with this crap, or even make reverse engineering easier

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

    If you have a static container, wouldn't it be a good practice to check if the access is out of bounds? Additionally, you could do something to handle the out-of-bounds access. I understand that the purpose of the video is to show that C doesn't protect against rookie or accidental mistakes, but it also demonstrates that it gives you more freedom in what exactly you want to happen.

  • @teainnit27
    @teainnit27 День тому +1

    As Bjarne Stroustrup once said "C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off."

  • @onee
    @onee 5 місяців тому +65

    That intro though 😂

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

      @@onee 🤣🤣🤣

  • @GuigasJr
    @GuigasJr 6 місяців тому +28

    If you leave this the problem isn't the language. It's just a simple size check, every c programmer knows you have to do it

    • @shringe9769
      @shringe9769 6 місяців тому +5

      But humans make mistakes, don't you think the compiler should be checking for this kind of stuff?

    • @notjebkerman6207
      @notjebkerman6207 6 місяців тому

      @@shringe9769 It can, if you use -Wall or a similar flag.

    • @goatsfluff
      @goatsfluff 5 місяців тому

      @@shringe9769Sounds reasonable, but the more the compiler has to check, the longer the compiling will take. The fact of the matter is that humans are stupid, evil... and they make mistakes. And you can't possibly defend against all of that.

    • @conorstewart2214
      @conorstewart2214 5 місяців тому +12

      @@shringe9769 humans making mistakes can lead to issues in any language. Testing should catch issues like this if you do it properly. It’s really not that difficult to remember either, any time you receive input check it is valid. Relying on the compiler to catch issues is how you end up with programs with loads of bugs and security issues. The programmer should always focus on writing the best and safest code they can, the compiler is just there for extra protection, if something like this isn’t caught by the programmer or during testing then you have major issues with your programmers and testing procedures.

    • @bgdgdgdf4488
      @bgdgdgdf4488 5 місяців тому

      ​@@shringe9769you can statically analyze c. You can even do a lot with gcc with the right compiler options. You are literally complaining about a solved issue. Just because you didn't know about it doesn't make it an issue.

  • @Brad_Script
    @Brad_Script 6 місяців тому +90

    This is easily detected by GCC if you enable certain warnings (-Wall). This is really only unsafe if you are working with dynamic memory.

    • @hwstar9416
      @hwstar9416 6 місяців тому +4

      even then you can enable sanitizers and get the exact line of the errors.

    • @bracco23
      @bracco23 6 місяців тому +12

      GCC can only do static analysis, which might pick up some of the errors but not all of them. Sanitizers work at runtime and have a performance hit, they are useful for testing but not good for production.

    • @sethkills
      @sethkills 6 місяців тому +1

      Dynamic memory not necessary, just a lack of input validation.

    • @Alfred-Neuman
      @Alfred-Neuman 6 місяців тому

      Hum, yeah... That's why I only code in VBA, the best and the most powerful programming language in the world!

    • @jhgvvetyjj6589
      @jhgvvetyjj6589 6 місяців тому +3

      It can also be unsafe with fixed size and static arrays if the array index is unknown at compile time.

  • @RedFlame64
    @RedFlame64 Місяць тому +4

    Bro for a moment I thought that I was on the wrong video 💀💀

  • @spikes1210
    @spikes1210 10 днів тому +1

    “No thank you!” Totally got me

  • @Maklaka
    @Maklaka 5 місяців тому +9

    I literally cackled out loud in front of my wife with that intro. So good.

  • @w4439
    @w4439 6 місяців тому +6

    My fun (or dumb) fact from this past week: You can store the state of 8 binary elements into a single char with the

  • @mikaelpaulin2811
    @mikaelpaulin2811 5 місяців тому +4

    This is called freedom. And that's why C will always be the GOAT of coding languages.

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

      you meant c++

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

      @@anon1963 c++ < c, the truthfulness of this statement is proof

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

      @@anon1963 OOP is an exceptionally bad idea which could only have originated in California - Dijkstra

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

      @@Negs42 don't believe everything you see on the internet - Albert Einstein

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

      @@anon1963 stop using quotes that aren't attributed to Einstein - Albert Camus

  • @turockozenji1378
    @turockozenji1378 5 місяців тому +1

    my man, best vid ive seen today

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

    Possibly you might find "-Wall" at least a slight improvement.
    Maybe "-Werror" too.
    Not that either makes C perfectly safe... But you should use the tools that are available

  • @Subxenox15
    @Subxenox15 5 місяців тому +10

    If you want to catch a fish, don't ask the fish how, ask the fisherman.

  • @cerberusrap
    @cerberusrap 6 місяців тому +20

    I don't use C but i turned into paranoid. I restricted all inputs as hell in my first web app xD

    • @Brad_Script
      @Brad_Script 6 місяців тому +13

      you are supposed to do that regardless of what programming language you are using. Always check the size and the value of the input.

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

      it's not paranoia, it's called "being good at programming". That's how it should be done.

    • @pedrofelipefreitas2666
      @pedrofelipefreitas2666 3 місяці тому

      You're 100% correct, you should always check whether the input is valid or not, even if it's not size.

  • @NikolaNevenov86
    @NikolaNevenov86 6 місяців тому +58

    what it is the chance a skilled C programmer allows users to write to an array that could go out of bounds with no size checks?

    • @RPBiohazard
      @RPBiohazard 6 місяців тому +42

      The rust simps would get very angry with you if they could read

    • @mathiaspedersen2001
      @mathiaspedersen2001 6 місяців тому +40

      It happens all the time, even in peer reviewed code. You can write a hundred thousand lines of code, and you only need to slip up once.

    • @climatechangedoesntbargain9140
      @climatechangedoesntbargain9140 6 місяців тому +11

      SKILL ISSUE!!

    • @vadimemelin2941
      @vadimemelin2941 6 місяців тому

      Only in case if they show off by using array as an index, I guess

    • @NikolaNevenov86
      @NikolaNevenov86 6 місяців тому

      @baconmanthelegend I think it depends on what you are doing. If the language itself does not allow for out of bounds access, it means that when compiled it creates some kind of structure that tracks the size of the array itself. Thus every time you access it's adding a check. I would imagine that such a check will have some minute impact on performance. In the end it's still doing what you should be doing, it's just abstracted I assume. So you are trading control for convenience. Which I can understand... I love Python for it's garbage collection and typeless variables.
      Also the reason why C does that is simply because (the way I see it), C has no array, it only has pointers. The expressions `arr[i]` expands to something like `((void*)arr)*sizeof(type)*i`.
      It's a syntax sugar so people don't do the mentioned expression every time they want to access an element. So C itself and the compiler does not track the size of the array as in elements, but I assume only the size of the array in memory and I would assume mainly for the purpose of scope for the Stack.
      So I personally find it odd when C people speak of arrays as some kind of separate type from a pointer.

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

    I kinda like this lowlevelness of C. I often had this error when doing basic machine learning

  • @Atlastheyote222
    @Atlastheyote222 4 дні тому

    My professor described C and Java as like: “Java will not let you shoot yourself in the foot, C will help you aim the gun and will pull the trigger for you”

  • @iGrave
    @iGrave 6 місяців тому +14

    That intro mate - chefs kiss 👌

  • @astroorbis
    @astroorbis 6 місяців тому +8

    Bro hit the Levy gambit

  • @Satook
    @Satook 6 місяців тому +5

    The array will have 16,384 bytes. Unless you’re compiling with a weird word length. Good demo though!

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

      It depends on architecture. It is not stated in C ISO what length int should be. The minimum is stated and it is 2 bytes.

    • @Muskar2
      @Muskar2 3 місяці тому

      Never liked the varied sizes of C by default. Especially since overflows are a common mistake, but sometimes needs to be done intentionally. We always use stdint.h's types redefined to shorthands like u64 and s64.

  • @J.H.ALI000
    @J.H.ALI000 3 місяці тому +1

    I have been C Programmer and watching youtube since 2009. Why I just discovered your channel right now🤩💔.

  • @TroubledTrooper
    @TroubledTrooper 15 годин тому +1

    If you want to make a girl like you tell her that you prefer Rust code in the Linux kernel over C because it's more robust, accessible, modern and stable than C code, but that you are still open to any contributions to the kernel as long as they are commented well and are accepted by Linus Torvalds regardless of the personal choice of said programmer because open source development is a collaborative process like any project, but even more so.
    Trust me this works every time.

  • @RobotnikPlays
    @RobotnikPlays 4 місяці тому +26

    This is how the Heartbleed exploit worked. Fascinating how these sorts of exploits are found

  • @fazemc
    @fazemc 6 місяців тому +30

    I like to say. C language is a powerful language. It is up to you protected your code.

    • @mhavock
      @mhavock 6 місяців тому +6

      Also, only noobs program like his demo. most pro programmers do checks before they access memory etc

    • @PFnove
      @PFnove 6 місяців тому +1

      ​@@mhavockmost good programmers write safe code without checks (checks are for user input, that's where it's not your fault anymore)

    • @mhavock
      @mhavock 6 місяців тому +2

      @@PFnove ok, its obvious you know very little about programming. Checks are used for way more than users inputs. Other examples are APIs calls, network communication, memory/device allocation/init, and alot more. You probably one of those people that things rust is great when its really for people who are lazy and unprofessional coders in the first place. Go learn some programming and see how checks are used EVERYWHERE.

    • @PFnove
      @PFnove 6 місяців тому

      ​@@mhavocki know i'm probably not good, i've only been studying computer science for years and have only written 4 3d renderers from scratch and a couple more simple games such as infinite minesweeper, i surely don't know a thing about programming
      checks are only used when you have no control over what's happening, aka user input
      when you're idk, looping over an array or sampling a texture, you can write good code from the beginning so that no invalid offsets are generated at all and you don't need to waste cpu time (very expensive) to check them
      when you have user input on the other hand, you have no idea what kind of values you're gonna get, and you have to appropriately check them before using them

    • @PFnove
      @PFnove 6 місяців тому

      @@mhavock and if that's what you want to know, I use c++ and not rust

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

    This is done in JavaScript too, except it's not reasonable enough to give you an error and just sets all the missing elements to an "undefined" reference, the same thing you get if you access an index outside of the list (which should honestly also be an error).

    • @Lampe2020
      @Lampe2020 3 місяці тому +1

      JS really hates to error out, so it fails silently most of the time.

  • @sarjannarwan6896
    @sarjannarwan6896 3 місяці тому +1

    The transition was perfect.

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

    C is the adult of programming languages - you can do pretty much anything you want, but you're responsible for everything you do. And a huge part of what makes C so powerful is that it *DOESN'T* hold your hand every step of the way; doubly so as you can include inline Assembler and it doesn't even blink because you're working so close to the metal.

  • @dimitrioskalfakis
    @dimitrioskalfakis 6 місяців тому +16

    with great power comes great responsibility.

    • @nuelzemudio883
      @nuelzemudio883 4 місяці тому

      *with great power comes great electricity bill.

    • @Muskar2
      @Muskar2 3 місяці тому

      @@nuelzemudio883 Literally, but great control flow power leads to _lower_ electricity bills. Running performant software makes it feel like it's not even running, while a slow one spends a lot of resources (100x is not atypical) on many other things than actually solving the problem. And slow code is the norm in modern high level languages.

  • @caiomazzaferroadami
    @caiomazzaferroadami 6 місяців тому +9

    In which system does an int take 1 byte of space in memory? 🤔

    • @bigutubefan2738
      @bigutubefan2738 6 місяців тому +5

      char-acteristic systems

    • @cigmorfil4101
      @cigmorfil4101 6 місяців тому +10

      One with an 8-bit CPU: the Apple ][, CBM PET, BBC micro, TRS-80, etc.

    • @vibaj16
      @vibaj16 5 місяців тому +1

      none

  • @askholia
    @askholia 6 місяців тому +7

    I don't know how many times I've rewatched this and cracked up like it's the first time.

  • @Queeebo
    @Queeebo 4 місяці тому

    This might have been the best intro that I have seen this year ❤

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

    C has all the power and flexibility of Assembly, with all the maintainability and readability of Assembly.

  • @akulkis
    @akulkis 6 місяців тому +4

    It's easy to do such checks in C.
    1. Use a symbolic name for the array size, not a literal number
    2. Check the access vs the array size before attempting to access.... WHEN APPROPRIATE (the array index expression is based on input data and hasn't been validated yet). Internally generated array index values are predictable and shouldn't need to be validated.

    • @segueoyuri
      @segueoyuri 4 місяці тому

      = skill issue. This is basic basic stuff.

  • @Tomyb15
    @Tomyb15 6 місяців тому +6

    Guy has a wife and child you know 😂

  • @Darkl0ud_Productions
    @Darkl0ud_Productions 6 місяців тому +4

    "No thanks, I want to understand pointers."

  • @turboluck1023
    @turboluck1023 3 місяці тому +1

    C was designed to develop operating systems, which means you deal with all the memory and all the things, however the C standard Library makes it a general purpose language which it is very much bot designed for

  • @fcolecumberri
    @fcolecumberri 5 днів тому

    Even if you don't like OOP, use C++ instead of C. Put an internal rule in your teamwork to only use C++'s std::array (using .at()), std::shared_ptr, std::string and std::vector (using .at()) and the rest program like C. Just by doing that, you will remove almost every potential memory problem.

  • @cesardmora86
    @cesardmora86 3 місяці тому

    input validation has the following benefits:
    - reduce stress
    - prevent heart disease
    - improve sleep quality and overall healthiness

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

    The deadpan response killed me 😂💀

  • @T1Oracle
    @T1Oracle 3 місяці тому

    It's unsafe because you don't know what you're getting into. This is why vetting is important.

  • @ozdemirsalik
    @ozdemirsalik 17 днів тому

    Although it’s unsafe, it’s the definition of performance aside from the Assembly languages.

  • @RD-ni7qe
    @RD-ni7qe 3 місяці тому

    I love this intro so much, please just use it at the start of every vid.

  • @kaizoku-ou-23
    @kaizoku-ou-23 2 дні тому

    bro's hooking technic is awesome

  • @Muskar2
    @Muskar2 3 місяці тому

    C has a lot of legacy problems (like lacking good built-in bounds checking) but it's still one of the most powerful languages. Hopefully new imperative languages will come to better unite productivity and control flow.

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

    Yes sirrr. That's what C is. Full control and meaning

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

    Funny thing, there was an AI that refused to teach C to minors, because teaching something unsafe to minors is irresponsible. I forget the name of the AI, but it was hilarious and terrifying.

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

      @@rmt3589to be honest that sounds like kind of a responsible option lol

  • @penielmuthanga9530
    @penielmuthanga9530 4 місяці тому

    The fine gentleman has set his priorities right.🥂✨

  • @mage3690
    @mage3690 11 днів тому

    "Why would I do this, why would I just select the xth element like that." This aged like the finest of fine wines. Why indeed.

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

    bruh that “no thank you” had me dying 💀

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

    Man's got his priorities straight.

  • @meejmuas8686
    @meejmuas8686 4 місяці тому

    The offer at the beginning almost made me swipe. Low level coding saved this clip for me

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

    That is so dangerous. I would think the compiler would give a warning at compile.

  • @speedbird8326
    @speedbird8326 5 місяців тому

    Dude. Intro is GOLD !!

  • @OxfordGraduate
    @OxfordGraduate 3 місяці тому

    This was the best intro in the history of intros, forever subbed now

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

    this is so real, i would never do any of those things that he said. i know all of those things of course. but he said it all already.

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

    Truely brilliant opening.

  • @anuragtekam4588
    @anuragtekam4588 3 місяці тому

    That's actually the beauty of the C , you have control over almost everything.

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

    Not 4096 "bytes" but 4096 "ints"!
    A very important distinction

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

    It is unsafe because it will not complain. C treats you like a god.

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

    First: since it's a int, you have 4 * 4096 = 16384 bytes.
    Second: you can do that in most languages.

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

    The "No thankyou" everything 🤣🤣