Question: A C language preprocessor macro definition has the form: #define name replacement text Such a definition calls for a macro substitution of the simplest kind

A C language preprocessor macro definition has the form: #define name replacement text Such a definition calls for a macro substitution of the simplest kind - subsequent occurrences of the token name will be replaced by the replacement text, where name has the same form as a variable name and replacement text is arbitrary. It is also possible to define macros with arguments, so that the replacement text can be different for different calls of the macro. This form of "parameter passing" is essentially pass-by-name. Besides inheriting all the potential problems of pass-by-name, macro substitutions has problems of its own. Consider the following piece of code fragment. #define testNeg(x) if (x > 0) printf("Oouch ") ... if (a > b) testNeg(b); else printf("Aaargh"); printf("Thank you "); What is the output (if any) of the fragment if (i) a is 4 and b is 3, (ii) a is -4 and b is 3, and (iii) a is -3 and b is -4? What is the potential problem of the code fragment
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
