Unnecessary Parenthesis

Tom Karzes karzes at mfci.UUCP
Wed Jul 27 01:34:25 AEST 1988


In article <1401 at devsys.oakhill.UUCP> steve at oakhill.UUCP (steve) writes:
}I'm sorry I can't include the text I'm mentioning since I'm haveing net
}reply problems, but I'll fake it as best I can.
}In an absolute sense
}>   #define square(x)    (x * x)
}shouldn't be :
}>   #define square(x)    ((x) * (x))
}it should be :
}>   #define square(x)    (temp = (x),(temp * temp))
}in order to avoid problems with sending in a post incremented variable;

This doesn't work in general in C for a number of reasons.  First, C is not
an expression language, so you can't declare temp to be local to the
expression.  This means it has to either be global or defined by the client
(and of course, this requires fixing its type, but I won't complain about
that).  Second, even if you could declare it locally, you'd have to be
careful about the name you used to avoid a name conflict with a variable
used in the expression for x.



More information about the Comp.lang.c mailing list