Don't use function macros; they are problematic. Instead, declare the functions inline to obviate the need for function macros (see "Inline functions" on page 90 for restrictions). Like const
, inline functions follow the C++ scope rules and allow argument type-checking. Both member functions and nonmember functions can be declared inline. Consider this classic example:
#define SQUARE(x) ((x)*(x))
// and...
SQUARE(y++); // y incremented twice
When written as an inline, it is actually more efficient than the macro version. What's more, it's correct.
inline int Square(int x)
{
return x*x;
};
Square(y++); // y incremented once
[Contents]
[Previous]
[Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.
Generated with WebMaker