Actions

EmSys

CCoding Style - Parenthesize the macro body and arguments

From EdWiki

Revision as of 06:51, 7 March 2012 by Jshankar (Talk | contribs) (1 revision)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Parenthesize the macro body and arguments

Macros work by textual substitution: the parameters in the definition are replaced by the arguments of the call and the result replaces the original call, as text. This is a troublesome difference from function.

#define    Square(x)    ( x * x )

And invoked as

Square(z+1)

The expression will be expanded to ( z+1*z+1)

#define    Square(x)    ( (x) * (x) )