JK> You shouldn't be using macros in C++, try inline functions instead.
PH> Forgive my ignorance (I'm into C, and only know a little about C++),
PH> but why shouldn't I use macros in C++? Doesn't C++ like macros for
PH> some reason, or is it just a matter of style?
C++ has the 'inline' deal as part of the language so that
one of the main advantage for using macros is no longer valid.
Instead of using scope-busting, type-unsafe macros, you can get
the same functionality and performance from code that is type safe
and does respect scope.
JK> BTW, the problem with macros is that you can't call Sgn() with ie
JK> getchar(), because you'll finish getting two chars instead of one...
JK> explanation is lefto to the reader as an exercise.
PH> Oh yes, I understand that. When the macro is expanded, since the
PH> parameter is evaluated twice in the macro, getchar() will be called
PH> twice. The programmer using such a macro would have to take that into
PH> account and provide a variable for getchar() to store its return value
PH> in before passing the variable to the macro. Maybe that's not the best
PH> way to do things, but in most cases it'll do.
If you created an inline function, the programmer need not worry about
the implementation details.
--- Platinum Xpress/Win/Wildcat5! v2.0
---------------
* Origin: St. Louis Users Group (1:100/4)
|