On 09-Aug-97, Peter Haywood wrote to Kurt J. Tischer about Re: Signs of
numbers.
PH> #define Sgn(x) (x 0 ? 1 : 0)
You shouldn't be using macros in C++, try inline functions instead. But if
you insist with macros, put () around the arguments, ie:
#define Sgn2(x) ((x) 0 ? 1 : 0)
because:
Sgn(a == 0);
will expand to
(a == 0 0 ? 1 : 0)
that's equivalent to:
(a == (0 0) ? 1 : 0) /* Wrong */
and not to
((a == 0) 0 ? 1 : 0) /* Right */
as it is when using Sgn2().
BTW, the problem with macros is that you can't call Sgn() with ie
getchar(), because you'll finish getting two chars instead of one...
explanation is lefto to the reader as an exercise.
Javier Kohen [The_Crusher] http://jkohen.base.org
... Es medio boludo þ Boludo enano
-!- CrusherTag 0.3.2.
--- Terminate 5.00 UnReg
---------------
* Origin: The King of The Ring (4:900/748.3)
|