January 2020
Intermediate to advanced
532 pages
13h 31m
English
Macro hygiene refers to the ability to keep macro-generated code clean. It is referred to as hygiene because the generated code does not get polluted by other parts of the code.
Note that many other programming languages do not provide such a guarantee. The following is a C program that contains a macro called SWAP, which is used to exchange the value of two variables:
#include <stdio.h>#define SWAP(a,b) temp=a; a=b; b=temp;int main(int argc, char *argv[]){ int a = 1; int temp = 2; SWAP(a,temp); printf("a=%d, temp=%d\n", a, temp);}
However, running this C program yields an incorrect result:

It did not swap the ...
Read now
Unlock full access