Your videos on C are the best! I'm guessing only reason people aren't watching your videos because they're usually new to the language and just stick with the shortest and simplest videos out there. But I'm really glad that you're also teaching not so popular topics.
Thank you for the positive feedback Bilguun, I appreciate it. :-) The channel is a bit new and the growth has been good lately, so hopefully it keeps up and more people keep finding the content.
@@PortfolioCourses They will, you are the best tutor of C in my opinion and kinda in programming in general. I also have a suggestion for vid. Basically new programmers (including myself) are unware how process is created and how os automatically behind the scenes (I am guessing at this point) assigns such things like stdin stdout stderr for a process. Such things are extremely hard to google, but every low level programmer needs to know about it.
@@dzentsetsu5607 Thank you for the support and the video topic suggestion! 🙂 I've thought about covering some shell scripting one day, and that would touch on some of these ideas.
Wow, this is by far the best C programming playlist I have come across on TH-cam. Your teaching style is on point and the explanations are clear. Please keep the good content coming. I am happy that I found this channel. I write code for embedded systems, and we use macros a lot, this was so helpful. Thank you.
This is probably the best tutorial on C macros on TH-cam! Thank you for the great lesson! Also could you make a video on how to make makefiles + explain some basic compiler parameters.
I understand why you don’t want to add a “return” @ 17:17. For this example, the return will cause main() to finish. However, I’m a bit confused on why “max_int” sees the final line of the macro @ 18:18? Since the text is getting replaced, why doesn’t “max_int” see “int current_max = array[0];”? I.e., why does it not evaluate to “int max_int = int current_max = array[0];” with the rest of the macro following?
Indeed, and this can lead to surprises when the macro is used in an if() statement: E.g. this could does not compile: if (a == b) output("equal"); else output('unequal"); As you probably know (but others might not), the solution is to use a do {} while (0) construct: #define output(s1) do { printf("%s ", s1); } while (0) Now the if() statement does compile correctly.
If my understanding is correct, Function like macros are widely used in AUTOSAR architecture to make abstraction between the layers. (Automotive Domain)
When writing a funciton-like macro, ALWAYS place parentheses directly around the variables: WRONG: #define mult_by_two(x) (2 * x) This is wrong because "mult_by_two(3+4)" will be replaced with (2 * 3+4), which evaluates to 10. RIGHT: #define mult_by_two(x) (2 * (x)) Now, "mult_by_two(3+4)" is replaced with (2 * (3+4)), which evaluates to 14.
Unfortunately I can't make it run in Visual Studio. The compiler freaks out with the last macro, giving me errors that they don't make any sense. Like syntax error, unrecognized token, it does not recognize the if statement inside the macro. I promise, I don't have any of these. My code looks absolutely like yours. It's so frustrating, and I'm looking for another IDE for c/c++ on windows. I think I'll try CodeBlocks, but If you have in mind something better from your experience, please give me your suggestion. Anyway, thank you very much in advance.
I think using gcc would be best for compatibility. I've heard of some folks having success getting gcc on Windows with this: www.mingw-w64.org/. :-) You could even use an in-browser IDE if you just want to learn, they all use gcc "under the hood" and if it's only for learning the language it's fine.
The reason for your errors is that gcc has a feature called Statement Expressions. In contrast msvc doesn't. The issue is that you can't assign a block of code to a variable, the find_max macro generates invalid C code, like int foo = ({ .... current_max; });
Your videos on C are the best! I'm guessing only reason people aren't watching your videos because they're usually new to the language and just stick with the shortest and simplest videos out there. But I'm really glad that you're also teaching not so popular topics.
Thank you for the positive feedback Bilguun, I appreciate it. :-) The channel is a bit new and the growth has been good lately, so hopefully it keeps up and more people keep finding the content.
@@PortfolioCourses They will, you are the best tutor of C in my opinion and kinda in programming in general. I also have a suggestion for vid. Basically new programmers (including myself) are unware how process is created and how os automatically behind the scenes (I am guessing at this point) assigns such things like stdin stdout stderr for a process. Such things are extremely hard to google, but every low level programmer needs to know about it.
@@dzentsetsu5607 Thank you for the support and the video topic suggestion! 🙂 I've thought about covering some shell scripting one day, and that would touch on some of these ideas.
I totally agree!
finally found the perfect tutor for learning c programming :)
I teach classes about C in my University. Your videos are part of this. Very good content about C. Congratulations.
Wow, this is by far the best C programming playlist I have come across on TH-cam. Your teaching style is on point and the explanations are clear. Please keep the good content coming. I am happy that I found this channel. I write code for embedded systems, and we use macros a lot, this was so helpful. Thank you.
Thank you very much for the kind feedback Itaka, I'm really glad to hear that you enjoy the channel and teaching style. :-)
This is probably the best tutorial on C macros on TH-cam! Thank you for the great lesson!
Also could you make a video on how to make makefiles + explain some basic compiler parameters.
Thanks! :-) And yes, I'm hoping to make an "introduction to makefiles" video some day.
Concise and straight to the point, thank you sir
Loved this video! Learned tons about macros in a very simple and clear way! Thanks man!
Macros are so much fun. Good call on using the brackets. I actually just wrote my own min max macros and did not enclose them in brackets.
Agreed, they're fun to work with! :-)
best C programming channel on youtube:)
Thank you for the very positive feedback, it's much appreciated! :-)
Thank you for this video man!! really straight to the point and just all around good stuff!
You're welcome Edidiong, I'm glad that you enjoyed it! :-)
Quality content! Your explanation is very clear, thanks for sharing your knowledge!
Thank you. I am reading a book and was lost. This helps a lot.
You're welcome Michael! :-) I'm really glad to hear this was helpful for you, thanks for sharing that positive feedback.
I understand why you don’t want to add a “return” @ 17:17. For this example, the return will cause main() to finish. However, I’m a bit confused on why “max_int” sees the final line of the macro @ 18:18? Since the text is getting replaced, why doesn’t “max_int” see “int current_max = array[0];”? I.e., why does it not evaluate to “int max_int = int current_max = array[0];” with the rest of the macro following?
when you define output you attach a semicolon to the end which will result in an empty expression if you put another one at the end of your code
Indeed, and this can lead to surprises when the macro is used in an if() statement:
E.g. this could does not compile:
if (a == b) output("equal");
else output('unequal");
As you probably know (but others might not), the solution is to use a do {} while (0) construct:
#define output(s1) do { printf("%s
", s1); } while (0)
Now the if() statement does compile correctly.
the best so far ever education in C. Thank you very mush :)
You're very welcome Zain, and thank you for the positive feedback! :-)
Excellent explanation! Thank you Sir.
Thank you for these great vids 👏🏻👏🏻🙏🙏🙏the deeper i get into c the more i understand how valuable these vids truly are
You're very welcome Abdl, I'm glad you're enjoying the videos! :-)
If my understanding is correct,
Function like macros are widely used in AUTOSAR architecture to make abstraction between the layers.
(Automotive Domain)
That sounds like a good usage of function-like macros. :-) I've seen macros used a lot to address compatibility and portability issues in general.
Yes we use macros in Autosar
Thank you so much sir for tge time you put into making these nice videos...🎉
doing great job
but ur channel is underrated
Thank you very much for the kind words! :-)
@@PortfolioCourses ur welcome😇
@@PortfolioCourses i subbed u!
Awesome, welcome aboard! :-)
Sir,you are great.
When writing a funciton-like macro, ALWAYS place parentheses directly around the variables:
WRONG:
#define mult_by_two(x) (2 * x)
This is wrong because "mult_by_two(3+4)" will be replaced with (2 * 3+4), which evaluates to 10.
RIGHT:
#define mult_by_two(x) (2 * (x))
Now, "mult_by_two(3+4)" is replaced with (2 * (3+4)), which evaluates to 14.
Unfortunately I can't make it run in Visual Studio. The compiler freaks out with the last macro, giving me errors that they don't make any sense. Like syntax error, unrecognized token, it does not recognize the if statement inside the macro. I promise, I don't have any of these. My code looks absolutely like yours. It's so frustrating, and I'm looking for another IDE for c/c++ on windows. I think I'll try CodeBlocks, but If you have in mind something better from your experience, please give me your suggestion. Anyway, thank you very much in advance.
I think using gcc would be best for compatibility. I've heard of some folks having success getting gcc on Windows with this: www.mingw-w64.org/. :-) You could even use an in-browser IDE if you just want to learn, they all use gcc "under the hood" and if it's only for learning the language it's fine.
The reason for your errors is that gcc has a feature called Statement Expressions. In contrast msvc doesn't. The issue is that you can't assign a block of code to a variable, the find_max macro generates invalid C code, like int foo = ({ .... current_max; });
@@ILightWas Thanks
super!
Thank you Simona! :-)
You Cool ! MAN
Thank you! 😀
@@PortfolioCourses I subscribed your channel 😀
@@programacionpse3520 Awesome, welcome aboard! 🙂
cool
:-)