![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Sep 2004
Posts: 29
Rep Power: 0
![]() |
Multiple conditions in an #ifdef statement
I'm trying to add some test code to a previously written program, and I wanted it to be seperated from the rest of the code using #ifdefs so I can easily disable it. There are multiple test cases, but some of the test code is used for multiple tests.
Basically what I have is this: #ifdef TEST_1 // do stuff #endif #ifdef TEST_2 // do stuff #endif #ifdef TEST_3 // do stuff #endif And what I want is #ifdef TEST_1 OR TEST_2 OR TEST_3 // do stuff #endif Is that possible to do? Thanks |
|
|
|
|
|
#2 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
That's going to do the same as if you only had TEST_1 or TEST2 or TEST3 though. Why on earth would you want to handle only one case for 3 test cases?
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for." -- Socrates |
|
|
|
|
|
#3 |
|
Expert Programmer
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4
![]() |
You can have three #indef's and inside each one, set a flag. After the program finishes evaluating the three conditions, if the flag is on, do stuff. Don't forget to set the flag to false before the #ifdef's
|
|
|
|
|
|
#4 |
|
Hobbyist Programmer
Join Date: Oct 2005
Posts: 134
Rep Power: 4
![]() |
Or you could just do this:
#if defined(TEST_1) || defined(TEST_2) || defined(TEST_3) // do stuff #endif |
|
|
|
|
|
#5 | |
|
Newbie
Join Date: Sep 2004
Posts: 29
Rep Power: 0
![]() |
Quote:
As for the flag, that should work. Thanks. |
|
|
|
|
|
|
#6 | |
|
Newbie
Join Date: Sep 2004
Posts: 29
Rep Power: 0
![]() |
Quote:
Ok, thanks. This is more what I was looking for but I didn't know if that was possible. |
|
|
|
|
|
|
#7 | |
|
Professional Programmer
|
Quote:
|
|
|
|
|
|
|
#8 |
|
Newbie
Join Date: Sep 2004
Posts: 29
Rep Power: 0
![]() |
I just tested it and it appears to work exactly the way you typed it.
Thanks again. |
|
|
|
|
|
#9 | |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,260
Rep Power: 5
![]() |
Quote:
Keep in mind that some coding guidelines discourage (or disallow depending on the intent of the guidelines) use of the preprocessor for anything other than include guards in header files. |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|