We are all familiar with the working of macros in languages like C. There are certain situations in which macro expansions can lead to undesirable results because of accidental capture of identifiers.
The code is actually equivalent to:
x = 4, y = 9
The variable a declared in the scope of the main function is overshadowed by the variable a in the macro definition so a = 4 never gets updated (known as accidental capture).
Hygienic macros are macros whose expansion is guaranteed not to cause the accidental capture of identifiers. A hygienic macro doesn’t use variable names that can risk interfering with the code under expansion.
The situation in the above code can be avoided simply by changing the name of the variable in the macro definition, which will produce a different output.
x = 5, y = 9
This article is contributed by Palash Nigam. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- How a Preprocessor works in C?
- Printing "GEEKS FOR GEEKS" In Brainfuck
- Some time-saving tips for Linux Users
- What happens when we turn on computer?
- Determine the type of an image in Python using imghdr
- Print "Hello World" in C/C++ without using any header file
- Double Brace Initialization in Java
- Command line arguments in C/C++
- Pointers in C and C++ | Set 1 (Introduction, Arithmetic and Array)
- Nested printf (printf inside printf) in C
- Function Interposition in C with an example of user defined malloc()
- Function Pointer in C
- Multithreading in C
- Name Mangling and extern "C" in C++
- C function to Swap strings