Warn when using parameter marked as __unused

前端 未结 2 1174
独厮守ぢ
独厮守ぢ 2021-02-06 05:56

Using the -Wunused-parameter flag, you can enforce __unused for unused parameters, as a compiler optimization. The following code causes two warnings:

#include &         


        
2条回答
  •  粉色の甜心
    2021-02-06 06:18

    Another way to skin this cat is to remove (or comment out) the name of the parameter.

    int main ( int argc, char ** /* argv */ ) {
        printf("hello world. there are %d args\n", argc);
        return 0;
    }
    

    Now the compiler won't warn about argv being unused, and you can't use it, because it has no name.

提交回复
热议问题