Today, one of my colleagues told me another use of define, which I did not know before! I am very grateful to him for telling me that he is willing to share it with me. How can I "eat! Haha! So I want to record it and share it with you, and I will not forget it. Okay, now !!
First, let's look at an example:
This is common and can be used by everyone. But can it be used as follows?
Well, let's compile it to see what the situation is. <Strong? Http: www.bkjia.com kf ware vc "target =" _ blank "class =" keylink "> VcD4KPHA + ICA8aW1nIHNyYz0 = "http://www.2cto.com/uploadfile/Collfiles/20140319/20140319092240332.jpg" alt = "\">
Let's take a look at how the macro works! (Macro expansion: $: gcc-E-P tt. c> file. After opening the file, you will see it)
An error was found during compilation and I variable was redefined. Why?
Because the defined macros are expanded in the call place during compilation, variable redefinition occurs when two macro definitions FUN () are called in the same scope.
So is there any way to make this call correct? See the following:
After compilation, the error cannot be found. Why? Let's take a look at the expanded macro:
No error occurs because two different variables, i1, i2, are generated here ,.