From http://c-faq.com/style/strcmp.html, I learned the following convenience macro:
#define Streq(s1, s2) (strcmp((s1), (s2)) == 0)
I want
Here's a relatively dumb example, but it does have a different result:
#define Streq(s1, s2) (strcmp((s1), (s2)) == 0)
#define MyStreq(s1, s2) (strcmp(s1, s2) == 0)
#define s1 "foo", "blah"
int main() {
Streq(s1, "blah"); // Compiles and compares equal.
MyStreq(s1, "blah"); // Compiler error. Too many parameters.
}
Parentheses do sometimes matter, and it is a good idea to unconditionally insert them. Consider the following poor macro:
#define OP(a, b) (a * b) /* BAD */
Invoked as OP(x + 1, y + 1)
it will expand to x + 1 * y + 1, breaking the intended grouping. Parentheses prevent this problem.
If you read a macro definition with parentheses around each argument use, the author certainly had this issue in mind - even if those parens happen to be redundant for that macro.