Herbert Schildt says:
In some situations, real function should be used in place of function-like-macro, for example: where code size is to be minimized or where an argument must not be evaluated more than once.
What does he mean by "an argument must not be evaluated more than once?"
Evaluative arguments argue that something is good/bad, effective/ineffective, helpful/harmful, etc. They evaluate something based one of the follow three types of criteria: practical, aesthetic, ethical. They consider which set of criteria (practical, aesthetic, ethical) their audience is likely to be convinced by.
The ability to evaluate these arguments to determine their credibility involves analysis and critical thinking. However, by evaluating what you read, you will have a much better understanding of what the text is trying to say and whether you agree with it.
In order to determine whether an argument is valid or not, ask yourself: Supposing that the premises are or were true (whether they really are or not), must the conclusion be true? If the answer is yes, then the argument is valid. If the answer is no, then the argument is invalid.
Understanding Evaluations Evaluative arguments rely on judgements and appraisals, often regarding quality or performance Informal evaluative arguments take place daily Examples: awards shows, beauty pageants, best- or worst-dressed celebrities, literary prizes, political opinion polls, elections
EVALUATING ARGUMENTS. There are two questions to ask: 1. Does the conclusion follow from the premises? That is, is the argument valid? 2. Are the premises true (or at least justified)? Or, is the argument sound (or, at least, strong)? VALIDITY. In a valid argument, the conclusion follows from the premises.
In Module 4 we look at different types of arguments and you will be given ample opportunity to practice your competence at evaluating different kinds of arguments. We should take the arguments that we evaluate seriously, present them in their strongest form, and subject them to careful and deep analysis and assessment.
An argument's purpose is to compela listener to believe the conclusion on the basis of the reasons given in support. To be a good argument, it must supply agreeable reasons that make the conclusion seem clearly true. Thus, a good argument guides reason, whether or not it appeals to emotion.
Let's take a macro to calculate the maximum of two values:
#define MAX(a, b) ((a) < (b) ? (a) : (b))
Then we use it like this:
int x = 5; int y = 10; int max = MAX(x++, y++);
Then the macro is expanded to
int max = ((x++) < (y++) ? (x++) : (y++));
As you can see, the increment operation on either x
or y
will happen twice, not what would happen if you had a function where each argument you pass is evaluated only once.
Another important point is the use of parentheses in the macro. Let's take another simple macro:
#define MUL(a, b) a * b
Now if you invoke the macro as
int sum = MUL(x + 3, y - 2);
then the expansion becomes
int sum = x + 3 * y - 2;
Which due to operator precedence is equal to
int sum = x + (3 * y) - 2;
Often not quite what was expected, if one expects (x + 3) * (y - 2)
.
This problem is also "solved" by using functions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With