Thank you for treating your audience like adults. This is the right amount of fast-paced and insightful. I appreciate a video that is meant to inspire people to dig deeper.
The content and presentation is top notch. I also like your eloquent speech: I'm interested in low level programming, but even if i was not, I would probably listen to this vid.
I came across the training series on C/C++ from sharing developments on different sites. I'm glad I came across it. There are many training series on C programming language, but none of them are as detailed and connected as you described. Thank you for your efforts. Greetings from Turkey. Good work.
kay..thanks for this awesome series. Im a react native developer who is interested to learn thee nitty gritty of coding. but actually lacks the core concepts. will be following ODES series as i find the videos very enlightening👍
I randomly saw this on my TH-cam feed and so glad I watched. I don't even code in C but it was interesting learning something new! I hope to see more videos! :)
I really enjoy your videos as i had some experience with c++ and i almost understand all of just C. I think this video format is great for people who are already informed about basics, pointers and memory concepts. Love from Moscow, Russia
Hey Kay, this is really good class. I hope you take more of such classes, maybe involving more of gdb and valgrind and other mess which we usually face 🙂 Really really good work.
The presentation and whole video overall was very smooth, even though I already knew this stuff, I watched until the end. Subscribed, very good content.
I've been having a crisis of meaning lately; I love my work as a web dev, but every day I'm just writing bloat. I was looking for a good intro to C or embedded development; grateful the algorithm sent your channel to me 👍
The for-loop is syntactic sugar for a while loop with the following setup: initialization; while (condition) { increment; } and its equivalent for-loop for (initialization; condition; increment) { } EDIT: i think it's easier to think of a for-loop as: for (before; during; after) { } but that can be confusing too. "During" is the condition that is technically checked *before* running the , but one can say that it's constantly being checked *during* the loop. "Before" is self-explanatory, but "after" seems confusing. "After" is code run after the has done its thing.
I have a background in java and actually started in C last week, was openai to help me show examples etc but this video was very helpful, thanks so much!
I enjoyed this video. I liked how you connected everything together. I am a less than beginner level in C. I have been in Assembly for quite a while now. I have have bounced into all of these concepts during my own writes and you lay it out so nicely and I like how it doesn't have to be fast and skippy. The whole concept of a function returning data has bothered me for some time now. The concept is an abstraction from what is really happening. A function call is really just a sugary goto but with a fancy way to return to the next line after the goto. And when the function does return; it just cannot carry data with it - LOL. But it could have altered the values in the registers. And our ancestors created a fancy trick by altering the RAX (EAX, AX, AL, AH) register; then copying that new value into a variable on the caller side. This gave the illusion in our beloved gen 3 languages that a function may return a value. But it really didn't, it just changed a register value. My point is that now everyone wants to return big stuff from functions and it has just gone too far. Ok - thats my rant for the day. And your video supports my thoughts with realistic examples. Love it!
Thanks for the comment! Really enjoyed reading it. I'm looking forward to getting more into building up the 'function' abstraction through assembly in the next couple videos. Was just playing around with it today actually. Exciting!
For better or worse, this is the video I need to see. I am working on a modern immediate GUI for myself, for fun (and maybe 'profit' for as far as I can go with FOSS!). Better late then never I suppose! Edit: 2:22 *shoves nerd glasses* What you refer to as 'Lie-nuhx' is in fact, 'GNU + Linux' or simply the 'Linux' stack.
i like your way of giving the information good work really i have a little knowledge of C Language so i may ask you to teach me and others like me C Language like this way Thank you in Advance 😍😍😍😍😍
I really love your style of presenting the source, the structure of your story, and just the easy going nature of it all. I will gripe about using two spaces for indentation, so -1 point for that, but +2 points for showing simple macros so that I now no longer feel that I need to avoid them. Thanks! Oh and, printf is super slow because I believe it's monstrously complex, so that might be worth mentioning (plus security risks I believe). And is make really worth using?
Thanks! And all good points - I can definitely feel the complexity of printf coming through when I reach for it :) Re: make, with these videos questions like that are often a balancing act. Could use a plain shell script but then learners might not remember make at all and that can be confusing later, or could go for something more fully featured and then you're going to also have to include setup instructions and risk diverting attention. My angle is often trying to put people in a position where they've encountered the right set of things to then go build on the basics later - rather than taking a sophisticated approach early on and getting muddled. Could easily argue for other tradeoffs though! Anyway, thanks for the comment :)
@@neoeno4242 You're right about make and your approach. This was more of a personal curiosity, and not a comment on your content. I got inspired by Handmade Hero that a batch file or shell script will suffice because usually it's just a few lines of mkdir, copy, gcc and run. So I have come to rely on a simple VS Code "skeleton project" as I clumsily called it that does these things: build, debug, and test. Whatever language I'll use is not even important because the concept works for whatever I'm making. You done any video on git yet? VS Code and git are a match made in software heaven.
I liked the video, but honestly probably a bit too hard for beginners. Honorable mission though. In particular, the attempt to simplify some topics may actually end up misleading: on discussion about returning strings, I can see how you really try to explain variables' lifetimes but without mentioning them explicitly only focusing on the example. I would try to instead insist on the notion of lifetime and then go on explaining why callee variables on stack cannot outlive their lifetime and be accessible from parent (i.e. they "expire" upon return, and thus caller's attempt to access that now potentially overwritten stack memory is flawed). I would also showcase how a struct wrapping the fixed size array is possible due to return semantics.
Thank you for the video. Please review the memory dump you're showing. Each line should display 16 bytes, but yours only shows 8. Additionally, please verify the byte order. On most modern architectures, it should be little-endian, meaning the smaller byte appears first.
Working on it :) At the moment I'm working towards creating binary executables from scratch as a little milestone. That will involve spending a bit more time working with binary data, file formats, syscalls, and ASM. I think my planning will solidify in the next few months - will share more as that solidifies!
If the memory is allocated with malloc and returned, if we call printf it wont be corrupted no? That problem was because the array was on the stack? Very interesting videos an great teacher!
Yes that's correct! Though if we use malloc in the function then we will have to decide when to free or 'give back' that memory (since in C nothing will free it up automatically and if the function is called repeatedly this will eventually use up a lot of memory). So string functions in C instead typically take a pointer to a buffer as an argument and then alter that buffer. That way the caller is responsible for allocating and freeing memory however they see fit.
I tried printing junk data just like at 27:04 on my machine using Clang version 14.0.0-1ubuntu1.1, but the data was not junk. When I used GCC, I got a Segmentation fault. After some research, I found that by setting the -fsanitize=address and -fsanitize-address-use-after-return=always flags, it detects stack use and fails. I wonder why I couldn’t print a junk value on my machine.
Yes - it definitely has that advantage. Though it has some other disadvantages, for example that allocating memory takes a bit of time and someone has to remember to free it up. Many (not all) C programmers prefer fixed-length buffers to malloc for certain tasks. If you're used to higher level languages this might feel weird though!
@19:55 Is it padding, between two string addresses? exactly at 0x0014 (based on correct addressing). if it's not padding then why extra 00 stored in between two strings. I can understand the null pointer at the end of strings, but why extra zero at 0x0014
Good question - that one is just arbitrary. I wanted to indicate for the purposes of the demonstration that I'm not describing precisely where strings will definitely get put in memory. The values aren't packed perfectly so that people won't accidentally assume that they are. In the real world, there might be many reasons - could be padding/alignment, could be the C compiler is deciding to store other values there, could be other reasons, or it could be that they get packed perfectly!
@@neoeno4242 thank you for the explanation. I thought C is just like assembly(.align 4). But from your explanation, we can't be sure how data is packed/ordered in memory. I'm sad now.
at 8:32 i believe there is something off in how the sentence is composed logically. "...it just gets inlined straight into the file, and everything in the other C file gets chunked into the C file we are including from..." "...chunked into the file we are including from..." does it? Or am i missing something?
You are right, that might be a small mistake. For anyone looking at this later, it just does a simple copy and paste (from the other file into your file). By convention, we also generally separate code into two files "header files" (.h) contain code that you want to be copied into other files (you can #include them). Implementation files (.c) contain code that you don't want to (or can't) copy around. One thing to note is that you cannot copy function implementations, so leave the implementation in a .c file, and the declaration in the .h file. This lets you use the function in other places without having multiple functions with the same name causing a linking error.
Is it possible that the assert without printf could also fail at 25:10 because buffer variable is reallocated to something else? I am not sure why it is stated here that the program fails only after printf is added.
Because it's on the stack and the stack is changed after calling printf(). Literally any function which makes use of some stack space would have the same effect.
@@anon_y_mousse but even without modifying our program, it is possible that stack memory could be allocated or used by some other program and there is no gurantee this program would work everytime (without printf Or any other change) right?
@@vasantheee I certainly wouldn't depend on it being valid after the function call, but OS's typically will allocate a stack per thread or process, depending on configuration. However, depending on what the compiler does to your code, even if you don't make a function call, it's likely that data higher up on the stack could be instantly invalidated upon function return. For older chips and microcontrollers, if you have a stack at all, then all parameters would be passed on the stack, generally, and then upon return, anything allocated off the stack inside the function would be instantly invalidated. For newer chips, it's pretty much a given that parameters will be passed by register if you have few enough parameters, but the compiler might very well finagle your code such that it has to push and pop some data around the function call which would thus invalidate the array. In short, you don't have to worry about other programs running on the system invalidating your stack because your own program will likely do it without you directly seeing the effects.
@@vasantheee I would say we shouldn't ever count on it. The thing to remember, if you want to work with an array, pass it into the function. If you want it to be resizable, then pass the address of the pointer. If you want to do dynamic arrays, then consider using a struct and passing the address of that struct, say typedef struct { size_t length; int data; } array_t; and just replace int with whatever type you wish to have an array of. You could even make the array type something like int_array_t or array_int_t or whatever name you feel like.
19:13 - what the hell each 4 bits have its own address? x86 cpus can only address minimum a one byte(8 bit)... and other cpus, except microcontrollers( where part of memory can be 1-bit addressed for gpio)
Ah yes, my mistake - thanks for flagging. I mistakenly gave each digit its own address, which isn't correct! Should be something more like this: link.excalidraw.com/readonly/KooN4ScH7IO4QuRsZtEG
TL;DW Noob: Why does the program segfault? I'm too used to OOP! Expert: The stack does too good a job cleaning itself up, which is why you can't just return an array like that in your string concat function. Noob: Seriously, why doesn't it work like I expect it to? Expert: Because with great memory control comes great responsibility. Noob: So I can just make a big array at the beginning of the program and use that instead of worrying about free andMalloc? Expert: That's what I do in my prototypes anyway until I find it necessary to allocate such memory by hand. Noob: I'll just stick with JS and hope for the best. Expert: Wait a minute, you can still leak memory in J- Noob: _Sees browser crash due toOOM error_ Thanks anyway, I'll just stick with my abacus. At least that doesn't break on me when I least expect it to...
Excuse me, young fellow. May you please provide me with some advice on how to become a professional (or better yet, dangerous) C programmer. Thanks a bunch
By way of advice on going pro with C I'm not sure I have anything really revelatory - it does appear like safer systems languages like Zig, Go, Rust are gaining popularity lately. If you're looking into C though, common pro books I see recommended are: C Programming, A Modern Approach by K N King and The C Programming Language by Kernighan, Richie. On top of that, write a lot of code and ideally run it yourself day to day :) Why use the built in `ls` when you can make your own and feel all the pain when it doesn't work? Wishing you good fortune.
One of the best C classes that i have seen in my whole life, way better than the college classes i attended. I apreciate
Thanks :)
Ok first comment, i'm about follow along. we will see :)
Thank you for treating your audience like adults. This is the right amount of fast-paced and insightful.
I appreciate a video that is meant to inspire people to dig deeper.
Man I knew this stuff and still watched it to completion. You have a lovely style presenting and I could listen to you talk about nerdy topics all day
The best explanation of how memory works that I've ever seen. Very clear. Thanks for your effort.
Great job. I have to thank the youtube algorithm for suggesting your channel. Thanks a lot. Greetings from South America.
i agree with you and my greetings from Egypt 👏💪
The step by step visualization of all the memories involved was reslly well done. Thank you to spread knowledge.
Just watched this. The density of information is quite spot on.
The content and presentation is top notch.
I also like your eloquent speech: I'm interested in low level programming, but even if i was not, I would probably listen to this vid.
I came across the training series on C/C++ from sharing developments on different sites. I'm glad I came across it. There are many training series on C programming language, but none of them are as detailed and connected as you described. Thank you for your efforts. Greetings from Turkey. Good work.
Thanks for the video! I haven't used C in years and had forgotten how fun it is, this will be a great refresh for me :)
honestly such a refreshing video on C,
Gold mine of content. This deserves much more audience
Magnificent classes you give Dear Kay, most grateful to you and thanks for your efforts
kay..thanks for this awesome series. Im a react native developer who is interested to learn thee nitty gritty of coding. but actually lacks the core concepts. will be following ODES series as i find the videos very enlightening👍
I've recently started learning C, and this video is perfect. I really like the format and presentation. Thank you!
I need to learn C++ for work, and its also really complicated in my opinion. What do you think?
I randomly saw this on my TH-cam feed and so glad I watched. I don't even code in C but it was interesting learning something new! I hope to see more videos! :)
I really enjoy your videos as i had some experience with c++ and i almost understand all of just C. I think this video format is great for people who are already informed about basics, pointers and memory concepts. Love from Moscow, Russia
This is the best lesson on C I have ever watched. Thanks a bunch
C really is fun! And because it's been around for so long, used textbooks on Amazon are dirt cheap.
I don't see you making the same argument for Fortran and Pascal ;)
I wish you taught c#, I love the way you "teach".
Your content is PURE GOLD Kay, thank you!
Some of the best programming content on TH-cam!
the explanation of the function pointer in the memory space is great. well done.
Hey Kay, this is really good class. I hope you take more of such classes, maybe involving more of gdb and valgrind and other mess which we usually face 🙂 Really really good work.
I don't even know why I'm watching this since I've been using c++ for like 3 years now, still nice video
Poor hand writing is a sign of intellect':] You rock!
The presentation and whole video overall was very smooth, even though I already knew this stuff, I watched until the end. Subscribed, very good content.
Appreciate it!
Great video ! So much information, but is so well presented and clear !
I've been having a crisis of meaning lately; I love my work as a web dev, but every day I'm just writing bloat.
I was looking for a good intro to C or embedded development; grateful the algorithm sent your channel to me 👍
hello i love you this is literally the best c video on the internet
Thanks a lot for this, others would have taken at least 4 hours for this amout of information, really appreciate it
The for-loop is syntactic sugar for a while loop with the following setup:
initialization;
while (condition) {
increment;
}
and its equivalent for-loop
for (initialization; condition; increment) {
}
EDIT: i think it's easier to think of a for-loop as:
for (before; during; after) {
}
but that can be confusing too. "During" is the condition that is technically checked *before* running the , but one can say that it's constantly being checked *during* the loop. "Before" is self-explanatory, but "after" seems confusing. "After" is code run after the has done its thing.
I have a background in java and actually started in C last week, was openai to help me show examples etc but this video was very helpful, thanks so much!
Good explanatory content for beginning C programmers.
This is a work of art. Keep up with the good job. Im thankful for this resource
I enjoyed this video. I liked how you connected everything together. I am a less than beginner level in C. I have been in Assembly for quite a while now. I have have bounced into all of these concepts during my own writes and you lay it out so nicely and I like how it doesn't have to be fast and skippy. The whole concept of a function returning data has bothered me for some time now. The concept is an abstraction from what is really happening. A function call is really just a sugary goto but with a fancy way to return to the next line after the goto. And when the function does return; it just cannot carry data with it - LOL. But it could have altered the values in the registers. And our ancestors created a fancy trick by altering the RAX (EAX, AX, AL, AH) register; then copying that new value into a variable on the caller side. This gave the illusion in our beloved gen 3 languages that a function may return a value. But it really didn't, it just changed a register value. My point is that now everyone wants to return big stuff from functions and it has just gone too far. Ok - thats my rant for the day. And your video supports my thoughts with realistic examples. Love it!
Thanks for the comment! Really enjoyed reading it. I'm looking forward to getting more into building up the 'function' abstraction through assembly in the next couple videos. Was just playing around with it today actually. Exciting!
perfect for my reintroduction to the c programming language.
Just had to comment again and I’m a new subscriber. This was so good. You’re very intelligent and explain things well. Made all this seem very easy
What a calm person you are !:) First time I've watched your video. So let me check your playlists :)
This comment works roughly as you would expect it: you make an awesome video, I comment nice stuff.
Such an amazing talk...pure code and explanations.
youre awesome, kay! learning a lot from you. thanks!
thanks for this crisp, to the point video.
Thank you, your videos are very enjoyable to watch.
For better or worse, this is the video I need to see. I am working on a modern immediate GUI for myself, for fun (and maybe 'profit' for as far as I can go with FOSS!).
Better late then never I suppose!
Edit: 2:22 *shoves nerd glasses* What you refer to as 'Lie-nuhx' is in fact, 'GNU + Linux' or simply the 'Linux' stack.
Thanks for the lesson. I hope you keep up with producing awesome content.
You have a nice smoothing voice
This rules, someone lovely making nice videos about C what could be better
The clip cuts are nice to keep things moving, keep making educational videos plz
i like your way of giving the information good work really i have a little knowledge of C Language so i may ask you to teach me and others like me C Language like this way
Thank you in Advance 😍😍😍😍😍
Great content. Appreciate your hard work. Btw, could you make a video about C++ ?!
Great video, thanks! I'm using C to build a little hobby os for fun, and this is a nice refresher video :)
7:20 aaaand you’ve reimplemented godbolt :)
thank you yt! thank you Kay! can I request for a holy-C playlist !
Just added playlists to my todo list!
@@neoeno4242 pdf too, I find enterprise design architecture very hard , basic intermidate is on yt , I wish get to to projects live ( pre record ed)
I really love your style of presenting the source, the structure of your story, and just the easy going nature of it all. I will gripe about using two spaces for indentation, so -1 point for that, but +2 points for showing simple macros so that I now no longer feel that I need to avoid them. Thanks! Oh and, printf is super slow because I believe it's monstrously complex, so that might be worth mentioning (plus security risks I believe). And is make really worth using?
Thanks! And all good points - I can definitely feel the complexity of printf coming through when I reach for it :) Re: make, with these videos questions like that are often a balancing act. Could use a plain shell script but then learners might not remember make at all and that can be confusing later, or could go for something more fully featured and then you're going to also have to include setup instructions and risk diverting attention. My angle is often trying to put people in a position where they've encountered the right set of things to then go build on the basics later - rather than taking a sophisticated approach early on and getting muddled. Could easily argue for other tradeoffs though! Anyway, thanks for the comment :)
@@neoeno4242 You're right about make and your approach. This was more of a personal curiosity, and not a comment on your content. I got inspired by Handmade Hero that a batch file or shell script will suffice because usually it's just a few lines of mkdir, copy, gcc and run. So I have come to rely on a simple VS Code "skeleton project" as I clumsily called it that does these things: build, debug, and test. Whatever language I'll use is not even important because the concept works for whatever I'm making.
You done any video on git yet? VS Code and git are a match made in software heaven.
Not yet! Good idea though, thanks :)
bro is majestic
bro is trans
she is slaying physically and intellectually 💅
Agreed, what a fierce flow.
i really had fun watching this
Great teacher!
this is a great video! thanks for sharing
Wonderful job!
this series is grt.
I liked the video, but honestly probably a bit too hard for beginners. Honorable mission though. In particular, the attempt to simplify some topics may actually end up misleading: on discussion about returning strings, I can see how you really try to explain variables' lifetimes but without mentioning them explicitly only focusing on the example. I would try to instead insist on the notion of lifetime and then go on explaining why callee variables on stack cannot outlive their lifetime and be accessible from parent (i.e. they "expire" upon return, and thus caller's attempt to access that now potentially overwritten stack memory is flawed). I would also showcase how a struct wrapping the fixed size array is possible due to return semantics.
Such an interesting perspective - thanks for sharing, appreciate it and I'm sure others will too.
@neoeno4242 do you have a Discord server/are you a Discord user?
Thank you for the video. Please review the memory dump you're showing. Each line should display 16 bytes, but yours only shows 8. Additionally, please verify the byte order. On most modern architectures, it should be little-endian, meaning the smaller byte appears first.
This was wonderful. Thanks!
great video :)
This is awesome!
the first this I do in an empty main is allocate 5k array just for the sake of it. Feels great to allocate arrays and then free it
Very, very good !
Hi, I subscribed yesterday.
Nice video. And I like your shirt. It looks good on you.
Thanks!
Please make more C videos 😢🙏🏼🙏🏼🙇🏼🙇🏼Please please ❤
"those fast counters will know" lol
enjoy your video, thanks!
Thank you for this video
do you have a map of topics you plan to cover in the next10-15 videos?
Working on it :) At the moment I'm working towards creating binary executables from scratch as a little milestone. That will involve spending a bit more time working with binary data, file formats, syscalls, and ASM. I think my planning will solidify in the next few months - will share more as that solidifies!
If the memory is allocated with malloc and returned, if we call printf it wont be corrupted no?
That problem was because the array was on the stack?
Very interesting videos an great teacher!
Yes that's correct!
Though if we use malloc in the function then we will have to decide when to free or 'give back' that memory (since in C nothing will free it up automatically and if the function is called repeatedly this will eventually use up a lot of memory).
So string functions in C instead typically take a pointer to a buffer as an argument and then alter that buffer. That way the caller is responsible for allocating and freeing memory however they see fit.
can we have some cintent on testing (windows) ?
Very high quality channel
I tried printing junk data just like at 27:04 on my machine using Clang version 14.0.0-1ubuntu1.1, but the data was not junk. When I used GCC, I got a Segmentation fault. After some research, I found that by setting the -fsanitize=address and -fsanitize-address-use-after-return=always flags, it detects stack use and fails. I wonder why I couldn’t print a junk value on my machine.
watching this quite cool video feels a little bit like stealing for the goodness received for free!
Spec requirement: high tech title card. ☑️
3:47: "Lowercase Zero" xD
What text font are you using?
Largely: Monaspace Xenon for the code font, and Mona Sans for the rest. Sometimes I mix up the monaspace font families though :)
incredible
At 14:00 i think it should either be nums[0] = 0x10; nums[1]=0x20; etc or 0a 14 1e in memory
Isn't the second solution with malloc more flexible since there might some situations where you don't know length of the string at compile time?
Yes - it definitely has that advantage. Though it has some other disadvantages, for example that allocating memory takes a bit of time and someone has to remember to free it up. Many (not all) C programmers prefer fixed-length buffers to malloc for certain tasks. If you're used to higher level languages this might feel weird though!
12:46 unsigned char MAX should be +255 , am I wrong ?
great! video
@19:55 Is it padding, between two string addresses? exactly at 0x0014 (based on correct addressing).
if it's not padding then why extra 00 stored in between two strings. I can understand the null pointer at the end of strings, but why extra zero at 0x0014
Good question - that one is just arbitrary. I wanted to indicate for the purposes of the demonstration that I'm not describing precisely where strings will definitely get put in memory. The values aren't packed perfectly so that people won't accidentally assume that they are. In the real world, there might be many reasons - could be padding/alignment, could be the C compiler is deciding to store other values there, could be other reasons, or it could be that they get packed perfectly!
@@neoeno4242 thank you for the explanation. I thought C is just like assembly(.align 4). But from your explanation, we can't be sure how data is packed/ordered in memory. I'm sad now.
Sehr gut
at 8:32 i believe there is something off in how the sentence is composed logically.
"...it just gets inlined straight into the file, and everything in the other C file gets chunked into the C file we are including from..."
"...chunked into the file we are including from..." does it?
Or am i missing something?
You are right, that might be a small mistake. For anyone looking at this later, it just does a simple copy and paste (from the other file into your file).
By convention, we also generally separate code into two files "header files" (.h) contain code that you want to be copied into other files (you can #include them). Implementation files (.c) contain code that you don't want to (or can't) copy around. One thing to note is that you cannot copy function implementations, so leave the implementation in a .c file, and the declaration in the .h file. This lets you use the function in other places without having multiple functions with the same name causing a linking error.
Yes it's not super clear - thanks for flagging and also to @BoardGameMaker4108 for clarifying. Appreciate it.
thanks bro!
what code editor are you using here?
VS Code :)
Is it possible that the assert without printf could also fail at 25:10 because buffer variable is reallocated to something else? I am not sure why it is stated here that the program fails only after printf is added.
Because it's on the stack and the stack is changed after calling printf(). Literally any function which makes use of some stack space would have the same effect.
@@anon_y_mousse but even without modifying our program, it is possible that stack memory could be allocated or used by some other program and there is no gurantee this program would work everytime (without printf Or any other change) right?
@@vasantheee I certainly wouldn't depend on it being valid after the function call, but OS's typically will allocate a stack per thread or process, depending on configuration. However, depending on what the compiler does to your code, even if you don't make a function call, it's likely that data higher up on the stack could be instantly invalidated upon function return. For older chips and microcontrollers, if you have a stack at all, then all parameters would be passed on the stack, generally, and then upon return, anything allocated off the stack inside the function would be instantly invalidated. For newer chips, it's pretty much a given that parameters will be passed by register if you have few enough parameters, but the compiler might very well finagle your code such that it has to push and pop some data around the function call which would thus invalidate the array.
In short, you don't have to worry about other programs running on the system invalidating your stack because your own program will likely do it without you directly seeing the effects.
@@anon_y_mousse thank you. So we cannot count on the program being successful like it happened at 25:10 all the time, right?
@@vasantheee I would say we shouldn't ever count on it. The thing to remember, if you want to work with an array, pass it into the function. If you want it to be resizable, then pass the address of the pointer. If you want to do dynamic arrays, then consider using a struct and passing the address of that struct, say typedef struct { size_t length; int data; } array_t; and just replace int with whatever type you wish to have an array of. You could even make the array type something like int_array_t or array_int_t or whatever name you feel like.
19:13 - what the hell each 4 bits have its own address? x86 cpus can only address minimum a one byte(8 bit)... and other cpus, except microcontrollers( where part of memory can be 1-bit addressed for gpio)
Ah yes, my mistake - thanks for flagging. I mistakenly gave each digit its own address, which isn't correct! Should be something more like this: link.excalidraw.com/readonly/KooN4ScH7IO4QuRsZtEG
Honest question, are you a male or female? My 5 yo son asked this question!
computer science is super dense , bruv
TL;DW
Noob: Why does the program segfault? I'm too used to OOP!
Expert: The stack does too good a job cleaning itself up, which is why you can't just return an array like that in your string concat function.
Noob: Seriously, why doesn't it work like I expect it to?
Expert: Because with great memory control comes great responsibility.
Noob: So I can just make a big array at the beginning of the program and use that instead of worrying about free andMalloc?
Expert: That's what I do in my prototypes anyway until I find it necessary to allocate such memory by hand.
Noob: I'll just stick with JS and hope for the best.
Expert: Wait a minute, you can still leak memory in J-
Noob: _Sees browser crash due toOOM error_ Thanks anyway, I'll just stick with my abacus. At least that doesn't break on me when I least expect it to...
This is my fave one: th-cam.com/video/GcDshWmhF4A/w-d-xo.html
Excuse me, young fellow. May you please provide me with some advice on how to become a professional (or better yet, dangerous) C programmer. Thanks a bunch
By way of advice on going pro with C I'm not sure I have anything really revelatory - it does appear like safer systems languages like Zig, Go, Rust are gaining popularity lately. If you're looking into C though, common pro books I see recommended are: C Programming, A Modern Approach by K N King and The C Programming Language by Kernighan, Richie. On top of that, write a lot of code and ideally run it yourself day to day :) Why use the built in `ls` when you can make your own and feel all the pain when it doesn't work? Wishing you good fortune.
bruh you pretty as hell T_T
But what if want to live dangerously in C? 😂
Then use after free all you like 😈