What are the consequences of ignoring: warning: unused parameter

前端 未结 8 759
闹比i
闹比i 2020-12-29 23:48

I am working on a C++ project and I noticed that we have a number of warnings about unused parameters.

What effect could it have if these warnings are ignored?

相关标签:
8条回答
  • 2020-12-30 00:18

    If a method doesn't use a parameter then the first question that arises is that why is that parameter a part of the method's signature in the first place. These warnings do make sense since it is bad design that these are referring to and further, there is a little overhead as well that whenever this method is called, this parameter is pushed on the stack so, the best is to refactor the method and remove such parameters which do not have any use.

    Having said that, leaving these parameters doesnt harm a lot except for a little overhead that I mentioned.

    0 讨论(0)
  • 2020-12-30 00:23

    For a gcc specific way to disable the warning, you can use __attribute__((unused)) like

    void foo(int a, int b __attribute__((unused))) {
    
    }
    

    To ignore the second parameter. If your program relies on GCC technologies already, you can use that attribute to be 100% safe from that kind of warning.

    0 讨论(0)
提交回复
热议问题