TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: JAVIER KOHEN
from: PETER HAYWOOD
date: 1997-09-07 01:51:00
subject: Re: Signs of numbers

Groovy hepcat Javier Kohen jived with Peter Haywood on 21 Aug 97  14:40:06!
Re: Signs of numbers's a cool scene. Dig it!
 PH> #define Sgn(x) (x  0 ? 1 : 0)
 JK> You shouldn't be using macros in C++, try inline functions instead.
 
  Forgive my ignorance (I'm into C, and only know a little about C++),
but why shouldn't I use macros in C++? Doesn't C++ like macros for
some reason, or is it just a matter of style?
 JK> But if you insist with macros, put () around the arguments, ie:
  Yes, I knew that. I guess I forgot (in my admitted inexperience).
 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.
  Oh yes, I understand that. When the macro is expanded, since the
parameter is evaluated twice in the macro, getchar() will be called
twice. The programmer using such a macro would have to take that into
account and provide a variable for getchar() to store its return value
in before passing the variable to the macro. Maybe that's not the best
way to do things, but in most cases it'll do.
                                                  Wolvaen
... Blonde Klingons: because it was a good day to dye.
--- Blue Wave/RA v2.20
---------------
* Origin: The Gate, Melbourne Australia, +61-3-9809-5097 33.6k (3:633/159)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.