![]() If you define a variable var inside function foo, and it calls a function bar, which defines its own variable var, then there will be no error, because the variable defined in bar is different from the variable defined in foo. On the other hand, when functions get called, they have a new allocated stack frame for them and they act independently of the place where they were called. What happens once you build your program is that all occurrences of macros are “expanded” and replaced by the macro definitions. Well, macros are a text processing feature. Sure, they have a bit of a strange syntax, but they “behave” like normal functions. The first time I got introduced to macros, they seemed like normal function calls. If you don’t, then you can run into some pretty nasty errors which are hard to debug and discover. Your duty is to understand why using this programming feature is dangerous and what dangers it holds. Even if you don’t use them in your own project, there is a high chance you will encounter them somewhere else, such as a library. However, as a C or C++ programmer, inevitably, you will encounter macros in your coding life. ![]() ![]() ![]() Using macros can be extremely unsafe and they hide a lot of pitfalls which are very hard to find. ![]() This is not something which can be seen in modern programming languages (other than C++). One strange phenomenon when coding in C is using macros. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |