a clean macro to make a part of code obsolete
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: a clean macro to make a part of code obsolete

  1. #1
    Join Date
    Aug 2009
    Posts
    25

    Lightbulb 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

  2. #2
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,245

    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?
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  3. #3
    Join Date
    Aug 2009
    Posts
    25

    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

  4. #4
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,632

    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)
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    http://www.microsoft.com/visualstudio/eng/downloads

  5. #5
    Join Date
    Jul 2005
    Location
    Netherlands
    Posts
    2,011

    Re: a clean macro to make a part of code obsolete

    Quote Originally Posted by S_M_A View Post
    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

  6. #6
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,245

    Re: a clean macro to make a part of code obsolete

    Quote 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.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  7. #7
    Join Date
    Apr 2004
    Location
    England, Europe
    Posts
    2,492

    Re: a clean macro to make a part of code obsolete

    Quote Originally Posted by laserlight View Post
    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
    My hobby projects:
    www.rclsoftware.org.uk

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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center