Thread: Debugging code to remove #ifdef statements, and I have some questions.

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    5

    Question Debugging code to remove #ifdef statements, and I have some questions.

    Hi everyone,

    I'm debugging some code for the PCTV 80e TV Tuner (hoping to get it included in the v4l project), and I'm trying to figure out whether or not some #ifdef statements need to be removed or moved or just altered.

    I have things like
    Code:
    #ifdef DJH_DEBUG
              int x;
    #endif
    and some where they are in the middle of a select/case statement

    Code:
            case option1
            case option2
    #ifdef only for certain conditions
            case option3
            case option4
    #endif
            case option5
    Finally, I have one or two that are entire methods (which I think will have to be moved to the header, but I'm not entirely sure).

    In some of the cases, I think the original author just used the ifdef statements as comments, but I'm not positive--which is why I'm here.

    What I want to do is comment out the #ifdef statements, so they aren't compiled. In the first example, I want to comment out the entire code segment. In the second example, I just want to comment out the lines #ifdef and #endif, but leave the code intact. Same with the third example (where they use it for entire methods).

    Can I simply surround the #ifdef statements with comment tags, or do I have to remove them completely from the program? In other words, will this work for the two given examples?

    Code:
    /*#ifdef DJH_DEBUG
            int x;
    #endif*/
    and some where they are in the middle of a select/case statement

    Code:
            case option1
            case option2
    /*#ifdef only for certain conditions*/
            case option3
            case option4
    /*#endif*/
            case option5
    Thank you for any information, and have a great day
    Patrick.

    P.S. I wasn't sure if this belonged in the C Programming or this forum, as the question is somewhat generic, but my application is for a Linux-based program. So, please move the thread, if necessary.

  2. #2
    Registered User gardhr's Avatar
    Join Date
    Apr 2011
    Posts
    151
    Quote Originally Posted by PatrickDickey View Post
    Hi everyone,

    I'm debugging some code for the PCTV 80e TV Tuner (hoping to get it included in the v4l project), and I'm trying to figure out whether or not some #ifdef statements need to be removed or moved or just altered.

    I have things like
    Code:
    #ifdef DJH_DEBUG
              int x;
    #endif
    and some where they are in the middle of a select/case statement

    Code:
            case option1
            case option2
    #ifdef only for certain conditions
            case option3
            case option4
    #endif
            case option5
    Finally, I have one or two that are entire methods (which I think will have to be moved to the header, but I'm not entirely sure).

    In some of the cases, I think the original author just used the ifdef statements as comments, but I'm not positive--which is why I'm here.

    What I want to do is comment out the #ifdef statements, so they aren't compiled. In the first example, I want to comment out the entire code segment. In the second example, I just want to comment out the lines #ifdef and #endif, but leave the code intact. Same with the third example (where they use it for entire methods).

    Can I simply surround the #ifdef statements with comment tags, or do I have to remove them completely from the program? In other words, will this work for the two given examples?

    Code:
    /*#ifdef DJH_DEBUG
            int x;
    #endif*/
    and some where they are in the middle of a select/case statement

    Code:
            case option1
            case option2
    /*#ifdef only for certain conditions*/
            case option3
            case option4
    /*#endif*/
            case option5
    Thank you for any information, and have a great day
    Patrick.

    P.S. I wasn't sure if this belonged in the C Programming or this forum, as the question is somewhat generic, but my application is for a Linux-based program. So, please move the thread, if necessary.
    Deleting or commenting out the code is not the answer! You can control which statements are enabled during compilation (your compiler's documentation will list which flag to use) or, at the very least, by directly defining/undefining things at "the top of the source file". The latter is generally frowned upon though because it's more tedious, less flexible, etc...

  3. #3
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Sounds like your question really should be, are any of these ifdef blocks potentially obsolete, and could be removed, and are there any ifdef blocks where anything non-obvious is going on?

    The first step is to identify which of the ifdef blocks are actually being compiled in. The way to do this is to create a syntax error within the block, and try to compile. If the code is being compiled, you'll get a compiler error.

    After you've identified the ifdef blocks of interest, I'm not sure what your next step is. Are you just trying to generally clean this stuff up, restructure it differently?
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  4. #4
    Registered User
    Join Date
    Oct 2011
    Posts
    5
    Thank you for both of your replies. I realized this morning that I needed to clarify things a bit. The code is something that Devin Heitmueller started working on last year. He got it working (so that you can use the Pinnacle PCTV 80e USB Tuner in Linux), however it won't be accepted into the linuxtv project (or the kernel) because of "Coding Style issues". One of the issues are #ifdef statements in .c files. Essentially he said he's not going to waste his time cleaning the code up, so anyone that wants to is welcome to it. So, I'm trying to do that.

    As for the #ifdef statements, he more or less said "You have a working driver, so try removing them and see what breaks." Rather than remove them, and then have to try and figure out what they were, I wanted to comment them out. If I find that I need one, then I'll try moving it to a header file, or removing the #ifdef statements around the code. One of the files which has the majority of these is about 15,400 lines of code. So I'm not sure how much of it I would need to quote here to give you the right context.

    I guess my question (in reference to brewbuck's reply) is this: Which of these are just unnecessary debugging, which ones could be there without the #ifdef statements around them, and which ones could be moved to the header files?

    To give you a bit more context, the first code snippet that I posted (the #ifdef int i one) uses i in a for loop. So, does C automatically assign a data type to the variable in a for loop, or do you have to explicitly declare it as an int (or whatever type you're using)? Along that line, does C++ handle this differently? (the answer to this may explain the reasoning behind the #ifdef statement).

    If you're interested in the code, I have it up at a github site http://github.com/patrickdickey52761/PCTV80e should get you to the code. You'll probably want the second and then the topmost commit (as the second is all of the files, but the topmost fixed a stupid bug that I introduced). The files that I'm worried about are in the linux/drivers/media/dvb/frontends/drx39xyj directory.

    I will try introducing some errors, and see which ones it triggers on. I'm worried though that it may not hit on my computers, but it might on someone else's.

    Thanks for the answers, and have a great day.
    Patrick.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Questions regarding usage of #undef and #ifdef
    By TAZIN in forum Windows Programming
    Replies: 9
    Last Post: 01-22-2011, 10:37 AM
  2. need debugging questions....
    By shuaib.akram in forum C Programming
    Replies: 4
    Last Post: 03-01-2010, 07:09 PM
  3. How can i remove debugging information
    By lolguy in forum C Programming
    Replies: 8
    Last Post: 02-25-2009, 02:36 PM
  4. I don't see the use of ifdef/endif in the following code
    By Overworked_PhD in forum C Programming
    Replies: 4
    Last Post: 01-18-2009, 01:46 PM
  5. Debugging questions
    By Stan100 in forum C++ Programming
    Replies: 2
    Last Post: 04-14-2003, 01:56 PM