|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
Using macros with operator symbols
For reasons that make sense to my application, I want to have a macro defined that will change "FOO=x;" to "BAR+=x;". To do "FOO=x; BAR+=FOO;" would be horribly unwieldy, and would not work in this application. I have tried "#define FOO BAR+", but I get a syntax error on the "FOO=x;" line. I have also tried "#define FOO= BAR+=", but the equals sign is an invalid character in macro names. Is there some way to make this work my way, or am I going to have to do some other dirty work-around?
|
|
#2
|
||||
|
||||
|
Re: Using macros with operator symbols
What is the intention of your code? Are you trying to set FOO and increment BAR? Or are you just trying to increment BAR through some sort of alternative interface?
|
|
#3
|
||||
|
||||
|
Re: Using macros with operator symbols
Quote:
|
|
#4
|
||||
|
||||
|
Re: Using macros with operator symbols
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? |
|
#5
|
|||||
|
|||||
|
Re: Using macros with operator symbols
Quote:
Code:
#define FOO(x) (BAR += (x)) Code:
FOO(5); Code:
FOO=5 Code:
(BAR += 5); |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| heres the code. y this not working | omega | Programming | 16 | 31-03-2004 15:18 |