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

warning C138

I try to keep my code free of warnings even when using warning level 3. In my code there are some function pointers like
typedef void (*fptr)(mytype*)
but some of the functions defined with this signature do not need the parameter. Thus I used something like

void f(mytype *x) {
...
return;
x;
}

to avoid the warning unused local. This worked fine with C compiler version up to 5.05 but gives warning C138: expression with possibly no effect in version 6.00.
Any idea how to solve this?

Parents Reply Children
  • I'd suggest #define'ing a macro for unused arguments, so you can easily alter the definition to suit different compilers or optimization levels.

    My current definition for Keil, which generates no code or warnings at optimization levels 9 or 11, happens to be:

    #define UNUSED(arg) if (arg) {}
    
    void f (U8* x, U16 y)
        {
        UNUSED(x);  UNUSED(y);
    
        }
    

    There was a good thread on alternatives a while back, but the new knowledgebase search function isn't finding anything for me. Other possibilities include:

    arg = arg
    if (0) { arg = arg; }
    (a)
    ((void)(a))
    

    any or all of which might suit a particular compiler / lint toolset better.

    Many compilers (but not Keil) skip the warning, but still do prototype checking, if you don't name the parameter, but merely declare the type:

    void f (U8* /* x */, U16 /* y */)
        {
        }
    

    You could of course macro the comment if you wished.

  • "... the new knowledgebase search function isn't finding anything for me ..."

    I am wondering whether the search facility has forgotten everything.

  • I am wondering whether the search facility has forgotten everything.

    Nope. We just reindexed everything this evening. This takes about 20 minutes.

    Jon

  • I'm now using

    #define UNUSED_LOCAL(_l) ((_l)=(_l))
    This works fine both with C166 V6.00 and gcc 3.3.3 (-Wall -Wstrict-prototypes).