This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Compiler warning - why?

I am just learning C by starting on modifying an example program to do what I want it to do. But immediately get warning messages although the compiled program runs fine. Whenever I declare a variable I get the following warnings.

Measure.c(153): warning: #550-D: variable "Minn_flag" was set but never used
Measure.c(62): warning: #550-D: variable "Ret_flags" was set but never used

Ret_Flags is declare as a global at the head of a file, and used in two functions. Minn_flag is declared inside a function and used once. I dont understand because I am declaring and using variables right alongside others already used in the example. Those variables dont get errors, but mine do. I am sure it's basic but what am I doing wrong?

Thanks!

Parents Reply Children
  • Thanks, I was using the variables just to catch some values for testing. I thought that minn = 0; was enough to keep the compiler happy. But then I added minn = minn + 1 and the warning has disappeared. So I know what you mean.

    OK here's another one how can I comment chunks of C code out that I don't want compiled right now inside a function? I tried /* ..... */ But the existing comments stop that working. // on each line works but thats a pain #IF 0 ..... #ENDIF doesn't work, is there a trick or do I have to cut/copy into Notepad for instance?

    Excuse these simple questions, but the Forum is the only place I can ask. At least I am making some headway into C, which pleases me at least. Thanks!

  • "#IF 0 ..... #ENDIF doesn't work"

    Remember that 'C' is case-sensitive

    You need to write #if 0 ... #endif

    This can also be useful for trying-out alternative approaches:

    #if 1
    //do it this way
    #else
    //do it that way
    #endif
    
    
    

  • OK here's another one how can I comment chunks of C code out that I don't want compiled right now inside a function? I tried /* ..... */ But the existing comments stop that working. // on each line works but thats a pain #IF 0 ..... #ENDIF doesn't work, is there a trick or do I have to cut/copy into Notepad for instance?

    Why doesn't #if 0 work? If you're using #IF try lower case.

    Some editors have a feature to put comments in front of all selected line (in Visual Studio it's ctrl-k-c).

    You might want to start new threads for different questions to get more response.

    Regards,
    Joost

  • "the Forum is the only place I can ask"

    Try this: http://c-faq.com/

  • If this is a code with the existing comments,

    int i = 0;
    ...
    stmt 1
    /*stmt 3
    stmt 4
    stmt 5 */ // Already commented
    stmt 7
    ...

    How about commenting,
    /* int i = 0;
    ...
    stmt 1
    /*stmt 3
    stmt 4
    stmt 5 // */ // Already commented
    stmt 7
    ...

    */

  • Yep,
    "this Forum is the only place I can ask"
    Right,
    and the only place where we get whole chunk of programs

    "I cannot write your programs for you.?"

  • How about commenting,

    /* int i = 0;
    ...
    stmt 1
    /*stmt 3
    stmt 4
    stmt 5 // */ // Already commented
    stmt 7
    ...
    
    */
    


    1. It's very messy; 2. You end up with nested comments - which is probably why it didn't work for John in the first place. Definitely better to go for the preprocessor approach:

    #if 0
    int i = 0;
    ...
    stmt 1
    /*stmt 3
    stmt 4
    stmt 5 // */ // Already commented
    stmt 7
    ...
    
    #endif
    


    But we need John to explain why it was that this didn't work for him - it certainly should work!

  • I realise now what went wrong. I had been writing some assembler and had used $IF $ENDIF. Then I switched to the C code and switched to #IF #ENDIF, just didn't realise what the mistake was. I haven't tried it but I'm sure it will work. Thanks for the help.

  • "I haven't tried it but I'm sure it will work. "

    Quite so - as already noted, 'C' is case-sensitive, so #IF is not equivalent to #if

  • "Quite so - as already noted..

    "it certainly should work! "

  • yes of course #if #endif works. But being a rebel I have decided that for commenting chunks of text I don't like it because I cannot take advantage of the color and font settings to help the eye see whats not in the compile etc.

    With about four careful edit "replace all" commands its easy to change the /* .... */ style to all //.....

    Then I just use the /* ... */ to comment out the chunks, and color it a yellow so that it almost disappears. Works for me.

  • "I don't like it because I cannot take advantage of the color and font settings to help the eye see whats not in the compile etc."

    So get an editor that does colour it! ;-)

    Codewright can hide code that is inactive due to #if

    "I just use the /* ... */ to comment out the chunks"

    But don't you still end up with the problem of nested comments:

    /* -- Inactive code
       blah;
       blah; // Existing comment is now nested!
       blah;
    */
    


    Your editor might allow it, but your compiler might not

  • Hi Andy, I have just toured uvision3 and I couldn't find where you can select an alternative editor. Prior to using uvisions built in one I used one called UltraEdit which has some neat features. Dont know if it can color or hide everything between #if .. #endif though. I dont see myself going down the Codewright route it costs $299. As to the nested comments, uvision seems to work fine in all respects. Using the /* .. */ combined with a yellow text gives good visual feedback that the bit I want excluding is commented out. For what I am doing now it works fine. I still realise that #if .. #endif is more useful for other reasons. Also I dont really like the /* .. */ commenting I find the // ... gives a cleaner look to the code anyway. Would be nice if I could make a macro to save me typing the 4x "change all" edit commands!

  • "I have just toured uvision3 and I couldn't find where you can select an alternative editor"

    I don't think you can - you're stuck with the "integrated" one.
    However, there's nothing to stop you using an external editor, and just using uVision for building, debugging, etc.
    You can set up entries on the Tools menu to launch your own editor, and you can use the Key Sequences to have in start at the current location in the current file, etc;
    http://www.keil.com/support/man/docs/uv3/uv3_dg_toolmnu.htm

    There is a certain other 8051 tool vendor whose "IDE" is, in fact, CodeWirght. By downloading their demo version, you can effectively get a free Codewright!
    I couldn't possibly name names here, of course... ;-)

    "As to the nested comments, uvision seems to work fine in all respects."

    Now this is where you can come unstuck with stuff like nested comments. uVision is not your compiler - so it is perfectly possible that uVision could be happy to colour your nested comments as you like it, while the actual compiler would throw them out.
    The same applies to any other editor, of course.

    "I dont really like the /* .. */ commenting I find the // ... gives a cleaner look to the code"

    I entirely agree on that one.
    Shame that // isn't strictly "ANSI" C, though... :-(

  • BTW: Did your post just suffer from the mystery missing line breaks?

    http://www.keil.com/forum/docs/thread8601.asp