Quote:
|
Originally Posted by Dave Scheck
How about this...
#define incr(var,n) ((var) += (n))
Then your code would look like...
incr(x,10);
incr(y,5);
This allows a single macro to increment whatever variable is passed to it.
From your original question, though, you seem to be wanting to hide the BAR variable from the user. Is there a reason for that?
|
If you want to hide the variable, how about
Code:
#define FOO(x) (BAR += (x))
When you use the macro, then you will write
instead of
and the precompiler will output
(I wont go into the whys for the seemingly excess parentheses. We can go into that in a separate thread if desired.)