Information AboutHygienic Macro |
| CATEGORIES ABOUT HYGIENIC MACRO | |
| transformation languages | |
| macros, hygienic | |
|
THE HYGIENE PROBLEM In a programming language that has unhygienic macros, it is possible for existing variable bindings to be hidden from a macro by variable bindings that are created during its expansion. In C , this problem can be illustrated by the following fragment: #define INCI(i) {int a=0; ++i;} int main() { int a = 0, b = 0; INCI(a); INCI(b); printf("a is now %d, b is now %d ", a, b); } Running the above through the C Preprocessor produces: int main() { int a = 0, b = 0; {int a=0; ++a;}; {int a=0; ++b;}; printf("a is now %d, b is now %d ", a, b); } So the variable `a' declared in the top scope is never altered by the execution of the program, as the output of the compiled program shows: a is now 0, b is now 1 Note that some C compilers, such as Gcc , have an option like `-Wshadow' that warns when a local variable shadows a global variable, which would have caught the above problem. STRATEGIES In some languages such as Common Lisp , Scheme and others of the Lisp Programming Language Family , macros provide a powerful means of extending the language. Here the lack of hygiene in conventional macros is resolved by several strategies.
REFERENCES
|
|
|