I'm really liking your videos. You just became my go to person when I want to learn about some advanced C++ topics. I did my own experiment after watching this video. If someone really wants to truly understand the difference between a constant and a Macros in C or C++; one could simply try to print out the memory location of both, and as this video vividly explained, marcos are just preprocessor directive that replace your macros in your program, which are NOT stored in memory. Doing this experiment helped in finally understanding the difference between marcros and const variables. I strongly suggest everyone watching this video to do the same :).
I'm not sure what you mean by this: "the output of preprocessing macros offers better debugging" The main reason I said that is because constants have types which can be checked at compile time, while, macros don't. With macros, of course you will get a compile time error most of the time but it could be confusing. I guess, with enough experience it doesn't really matter
Is it possible to use a macro to define an element of an array? I tried it with int const sameVar and it didn't work (error on that line). I want to be able to change elements of my array using a variable that is easy to access. The other reason is that I have 3 columns in the array and 2 of them need to be the same value, but they are not in succession. They skip: myArray[3] { (x=zVar ), y , zVar }. Can this be done? Ultimately hoping to do this as a multidimensional array in C. Thank you! Peace
Hmm... for the most part the difference would be negligeble (but remains to be tested). I say that because, constants do actually get replaced by hard-coded values at compile time (similar as to macros) since compilers now understand that there is little benefit to allocating memory for those constants at runtime so they are just stored as literals
Hallo ! thank you again for the the high informative videos ! Please , i have a question that is depressing me now for 2 weeks ... It's about the Macro EOF (End Of File) ... "i'am using getline" I understand how to use it in an infinte while loop ... But please could you explain me how getline detect the end of file ? i know that Getline return the number of bytes that was read in success , and return -1 on failure or EOF ... But how Getline detect the end of file so it's return -1 ? i was searching on the internet for hours , the only answer that i found : ctrl+d to simulate the EOF on linux ... which is not the case if you want to develop a program that keeps reading the input line and detect the end of FILE by itself and not the USER ! i would be very happy if you could answer me ! Thank you .
an elaborative and explanatory video, feeling lucky that i have discovered this channel
I'm really liking your videos. You just became my go to person when I want to learn about some advanced C++ topics. I did my own experiment after watching this video. If someone really wants to truly understand the difference between a constant and a Macros in C or C++; one could simply try to print out the memory location of both, and as this video vividly explained, marcos are just preprocessor directive that replace your macros in your program, which are NOT stored in memory. Doing this experiment helped in finally understanding the difference between marcros and const variables. I strongly suggest everyone watching this video to do the same :).
C/C++ compilers are working ALWAYS in 4 phases:
1) Preprocessor (everything starting from #)
2) Compiler
3) Assembler
4) Linker
Wasn't the assembler optional?
Awesome videos. Really impressed with the direct, focused information.
i am now hooked up to your videos, you are the best teacher.😊🙃
Man, you're the best in RUclips. Thanks a lot. 👍❤️
Great discussion
The best
9:15 why would one prefer to use constants instead of macros (aka symbolic constants?) if the output of preprocessing macros offers better debugging?
I'm not sure what you mean by this: "the output of preprocessing macros offers better debugging"
The main reason I said that is because constants have types which can be checked at compile time, while, macros don't. With macros, of course you will get a compile time error most of the time but it could be confusing. I guess, with enough experience it doesn't really matter
So cool
Is it possible to use a macro to define an element of an array? I tried it with int const sameVar and it didn't work (error on that line). I want to be able to change elements of my array using a variable that is easy to access. The other reason is that I have 3 columns in the array and 2 of them need to be the same value, but they are not in succession.
They skip: myArray[3] { (x=zVar ), y , zVar }. Can this be done? Ultimately hoping to do this as a multidimensional array in C. Thank you! Peace
Hmm... I'm not entirely sure what you're asking. Can you send me the code so I can better understand?
9:45 how does one find the computational cost of variable dereferencing? And compare that to cost of macro/preprocessing?
10:15 I understand that there’s usually no difference if you’re using a “modern compiler”
Hmm... for the most part the difference would be negligeble (but remains to be tested). I say that because, constants do actually get replaced by hard-coded values at compile time (similar as to macros) since compilers now understand that there is little benefit to allocating memory for those constants at runtime so they are just stored as literals
Oh man, I wish I could hire you as a tutor for few hours. I have so much to ask you
Just send me a private message on discord.code-vault.net and we can figure out the details!
Thanks sir
9:55 constant const int
Hallo ! thank you again for the the high informative videos !
Please , i have a question that is depressing me now for 2 weeks ...
It's about the Macro EOF (End Of File) ... "i'am using getline"
I understand how to use it in an infinte while loop ... But please could you explain me how getline detect the end of file ? i know that Getline return the number of bytes that was read in success , and return -1 on failure or EOF ...
But how Getline detect the end of file so it's return -1 ?
i was searching on the internet for hours , the only answer that i found : ctrl+d to simulate the EOF on linux ... which is not the case if you want to develop a program that keeps reading the input line and detect the end of FILE by itself and not the USER !
i would be very happy if you could answer me !
Thank you .
I'll look into it