The Practice of Programming book says:
One of the most serious problems with function macros is that a parameter that
appears more than once in the definition might be evaluated more than once; if the
argument in the call includes an expression with side effects, the result is a subtle bug.
This code attempts to implement one of the character tests from :
#define isupper(c) ((c) >= 'A' && (c) <= 'Z')
Note that the parameter c occurs twice in the body of the macro. If i supper is called
in a context like this,
while (isupper(c = getchar()))
then each time an input character is greater than or equal to A, it will be
discarded and another character read to be tested against Z.
I do not understand how a char greater >= A can be discarded.
Since macro definitions are expanded textually into the program before the actual compilation,
would expand to
which by the short-circuiting rule for
&&callsgetchartwice iff it returns>= 'A'the first time and assigncthe value returned by the second call.