-
April 6th, 2010, 07:05 AM
#1
a clean macro to make a part of code obsolete
Hi
I have a simple macro which I use when I want to disable part of my code
Code:
#define OBSOLETE_CODE(x)
But using this macro when you want to make many lines obsolete in not good
and looks like
OBSOLETE_CODE(
// 100 lines of code
)
I want to have two macro's BEGIN_OBSOLETE and END_OBSOLETE like below
Code:
BEGIN_OBSOLETE
// 100 lines of code
END_OBSOLETE
How should i achieve this as the following commands DO NOT work
Code:
#define BEGIN_OBSOLETE OBSOLETE_CODE(
#define END_OBSOLETE )
Thanks
-
April 6th, 2010, 07:18 AM
#2
Re: a clean macro to make a part of code obsolete
Why not just use #if OBSOLETE or #ifdef OBSOLETE? But if the code is really obsolete, why not just remove it?
-
April 6th, 2010, 07:30 AM
#3
Re: a clean macro to make a part of code obsolete
My code is unstable currently and I want just to disable some part of it without removing it
maybe i decide to include that part again
#ifdef is a good solution but I was wondering if there is any other choice
-
April 6th, 2010, 05:37 PM
#4
Re: a clean macro to make a part of code obsolete
Why not just comment the code out? If you use the block comment/uncomment command (select a block and Ctrl+K, Ctrl+C / Ctrl+K, Ctrl+U in VC) it's also easier to reactivate the code part by part (no need for adding #ifdef / #endif pairs)
-
April 8th, 2010, 07:05 AM
#5
Re: a clean macro to make a part of code obsolete
Originally Posted by S_M_A
Why not just comment the code out? If you use the block comment/uncomment command (select a block and Ctrl+K, Ctrl+C / Ctrl+K, Ctrl+U in VC) it's also easier to reactivate the code part by part (no need for adding #ifdef / #endif pairs)
The problem with that approach is that it doesn't work if there is already a block comment in your code or if you want blocks within blocks.
Code:
void foo()
{
/*
/*
*/ // comment ends here
*/ // compiler error
}
Cheers, D Drmmr
Please put [code][/code] tags around your code to preserve indentation and make it more readable.
As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky
-
April 8th, 2010, 07:09 AM
#6
Re: a clean macro to make a part of code obsolete
Originally Posted by D_Drmmr
The problem with that approach is that it doesn't work if there is already a block comment in your code or if you want blocks within blocks.
The "block comment" S_M_A referred to basically involves prepending // to each of the selected lines.
-
April 8th, 2010, 08:38 AM
#7
Re: a clean macro to make a part of code obsolete
Originally Posted by laserlight
Why not just use #if OBSOLETE or #ifdef OBSOLETE? But if the code is really obsolete, why not just remove it?
Or even better, give the macro a meaningful name like OLD_V4_CODE_USING_LISTS
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|