You actually don't *need* to write `return 0;` in your C or C++ main function. The main function is a special function which acts as an entry point, and the OS will return with a status code its-self depending on whether it was able to finish successfully or not. There is a macro named "EXIT_SUCCESS" and "EXIT_FAILURE" which is akin to returning successfully (or unsuccessfully with the latter macro) depending on the platform that you could return from. So yeah, you don't have to write "return 0;" in your main function, but for any other function which does have a return type, you do need to return something.
@@lane1313 Thank you. I'm kind of still trying to wrap my head around this way of saying the return type, because coming from Haskell, a function is an expression of sort that is reduced to a simpler one or a value, so it's kind of, for now, weird to say what is the return type, but it seems to be that the reduction itself has some kind of a return type, and because the reduction is stateful, so changing something, the return type can be something else, right? So I'm trying to understand the implications of this return expression in C.
@@domagojding So return statements simply mean in layman's terms "Stop what you're doing, and send this back to where it was expected." In functions, return statements state that the function is finished being executed and that either a value, object, or address (if you're returning a pointer of something stored in the heap/dynamic memory region) is to be given back. Same with loops. You can add a return statement in a for or while loop to signify that the loop is to halt and a value is to be stored in whatever scope that it's in. Does that make sense?
@lane1313 You know, the interesting thing is that it does make sense in the sense that the words make sense to me, but I still am having, you know, much difficulty in unwrapping or what would be the best word to, you know, understand this, this, do I call it mental model of evaluation? Because I'm kind of, I'm kind of giving a lot of statements to everyone else, like being a big boss, and from functional programming, which is kind of more, well, maybe that's not fair to say now, but it's, it's like the level of communication is, it's a bit different in the sense that I, I have many functions that do one thing, and if I want to change the output of a function, I transform it or I, well, I transform it in the sense that there is another function that, that externally looks like changing state, but the state is not changed. So it's, I think it's very hard for me now to explain what I mean in a few words, but maybe the, the number of words for now shows, shows still the difficulty in the way I try to understand this imperative model of computation.
@@domagojding I think you should give yourself some credit. You're obviously coming from a different world of programming, and in a sense, throwing yourself into the deep end making a programming language (even if it's just following a guide) in C, which is a whole different programming paradigm. So you should show yourself some grace and continue enjoying the journey of learning C and making this wonderful project. Functions can in fact, do multiple things, however, they can only return one thing at a time when you specify a return type (such as int, float, etc). A return statement can involve an expression (such as for example 5 + a). When the OS reaches the return statement in the stack frame (the stack frame if you're unaware, is the place in memory where the function is being kept. You might learn about function pointers later) it executes the code contained within it one line at a time. If the function has a return type, it'll be expecting a return statement before exiting the scope, which is what the compiler checks for. Once it reaches that return statement, it copies the value that's being returned into memory, and moves it back into the scope where the function was called and if it's being called in an expression like an assignment, it'll be placed where the callee' expects it. This is why you can call different function from within functions and assign values to variables from within functions. Let me know if that doesn't make sense or if I should reword something.
@lane1313 Hello, thank you for the comments. When you say if it makes sense or not, I think it does make sense, but more like I still don't understand, I still don't have the motions, so to say, of how the imperative model works. And I guess I go from word to word, and even if I kind of understand what it does, after I read the whole thing, for example, what you wrote, I'm not sure what I read. And then I go back and I read it, so I guess it just needs more practice, and doing the same thing. So I'll see how it goes. I tried to reflect on what you said in the video, in my newest video, the stream, Build Your Own Lisp, the third part. And yeah, but I'll reread your comment more, and I will let you know how it makes sense, or if rewording something helps. So again, thanks for the comment.
Which font are you using in your terminal, please?
@@hrqmonteiro iosevka
You actually don't *need* to write `return 0;` in your C or C++ main function. The main function is a special function which acts as an entry point, and the OS will return with a status code its-self depending on whether it was able to finish successfully or not. There is a macro named "EXIT_SUCCESS" and "EXIT_FAILURE" which is akin to returning successfully (or unsuccessfully with the latter macro) depending on the platform that you could return from. So yeah, you don't have to write "return 0;" in your main function, but for any other function which does have a return type, you do need to return something.
@@lane1313 Thank you. I'm kind of still trying to wrap my head around this way of saying the return type, because coming from Haskell, a function is an expression of sort that is reduced to a simpler one or a value, so it's kind of, for now, weird to say what is the return type, but it seems to be that the reduction itself has some kind of a return type, and because the reduction is stateful, so changing something, the return type can be something else, right? So I'm trying to understand the implications of this return expression in C.
@@domagojding So return statements simply mean in layman's terms "Stop what you're doing, and send this back to where it was expected." In functions, return statements state that the function is finished being executed and that either a value, object, or address (if you're returning a pointer of something stored in the heap/dynamic memory region) is to be given back. Same with loops. You can add a return statement in a for or while loop to signify that the loop is to halt and a value is to be stored in whatever scope that it's in. Does that make sense?
@lane1313 You know, the interesting thing is that it does make sense in the sense that the words make sense to me, but I still am having, you know, much difficulty in unwrapping or what would be the best word to, you know, understand this, this, do I call it mental model of evaluation? Because I'm kind of, I'm kind of giving a lot of statements to everyone else, like being a big boss, and from functional programming, which is kind of more, well, maybe that's not fair to say now, but it's, it's like the level of communication is, it's a bit different in the sense that I, I have many functions that do one thing, and if I want to change the output of a function, I transform it or I, well, I transform it in the sense that there is another function that, that externally looks like changing state, but the state is not changed. So it's, I think it's very hard for me now to explain what I mean in a few words, but maybe the, the number of words for now shows, shows still the difficulty in the way I try to understand this imperative model of computation.
@@domagojding I think you should give yourself some credit. You're obviously coming from a different world of programming, and in a sense, throwing yourself into the deep end making a programming language (even if it's just following a guide) in C, which is a whole different programming paradigm. So you should show yourself some grace and continue enjoying the journey of learning C and making this wonderful project.
Functions can in fact, do multiple things, however, they can only return one thing at a time when you specify a return type (such as int, float, etc). A return statement can involve an expression (such as for example 5 + a). When the OS reaches the return statement in the stack frame (the stack frame if you're unaware, is the place in memory where the function is being kept. You might learn about function pointers later) it executes the code contained within it one line at a time. If the function has a return type, it'll be expecting a return statement before exiting the scope, which is what the compiler checks for. Once it reaches that return statement, it copies the value that's being returned into memory, and moves it back into the scope where the function was called and if it's being called in an expression like an assignment, it'll be placed where the callee' expects it. This is why you can call different function from within functions and assign values to variables from within functions.
Let me know if that doesn't make sense or if I should reword something.
@lane1313 Hello, thank you for the comments. When you say if it makes sense or not, I think it does make sense, but more like I still don't understand, I still don't have the motions, so to say, of how the imperative model works. And I guess I go from word to word, and even if I kind of understand what it does, after I read the whole thing, for example, what you wrote, I'm not sure what I read. And then I go back and I read it, so I guess it just needs more practice, and doing the same thing. So I'll see how it goes. I tried to reflect on what you said in the video, in my newest video, the stream, Build Your Own Lisp, the third part. And yeah, but I'll reread your comment more, and I will let you know how it makes sense, or if rewording something helps. So again, thanks for the comment.