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

Add DISABLEWARNING support to C51?

The new BL51 option to disable specific warning messages is very nice! I would also like to have this capability in the C51 compiler (finer-grained control than WARNINGLEVEL). Specifically, there are times when I want to disable warning C280 (unreferenced local variable) when I know that I will not reference a parameter to the subroutine, and then re-enable that warning for subsequent functions in that module. For example:

#pragma DISABLEWARNING(280)
void funct1( char p1, char p2 )
{
// this function does not need p1
do something with p2, ignore p1
}
#pragma ENABLEWARNING(280)
void funct2( char p1, char p2 )
{
//this function SHOULD use both params
// so I want the warning if I mess up
}

Parents
  • I second that!

    Or maybe something like

    #pragma unused p1
    This is a particularly common problem when writing state machines using function pointers, as all the functions must have the same set of parameters - whether they need them or not.
    I have yet to come across a compiler which handles this well. :-(

    Keil makes the problem worse as it gives the same message, "unreferenced local variable," for both parameters and real local variables! :-(

    You could try something like:
    void funct1( char p1, char p2 )
    {
       p1 = p1; // dummy - does nothing, stops warning.
       do something with p2...
    }
    I think C51 is smart enough to avoid generating any code for the p1=p1, but it might depend on the optimisation level? (note that some compilers will give a warning such as "code with possibly no effect" in this case).

    BTW: Note the use of &ltpre&gt and &lt/pre&gt tags for code extracts - see the Tips for Posting Messages in the sidebar to the left.

Reply
  • I second that!

    Or maybe something like

    #pragma unused p1
    This is a particularly common problem when writing state machines using function pointers, as all the functions must have the same set of parameters - whether they need them or not.
    I have yet to come across a compiler which handles this well. :-(

    Keil makes the problem worse as it gives the same message, "unreferenced local variable," for both parameters and real local variables! :-(

    You could try something like:
    void funct1( char p1, char p2 )
    {
       p1 = p1; // dummy - does nothing, stops warning.
       do something with p2...
    }
    I think C51 is smart enough to avoid generating any code for the p1=p1, but it might depend on the optimisation level? (note that some compilers will give a warning such as "code with possibly no effect" in this case).

    BTW: Note the use of &ltpre&gt and &lt/pre&gt tags for code extracts - see the Tips for Posting Messages in the sidebar to the left.

Children