c++ - 怎么样让编译器对某些函数不再抱怨warning: unused parameter ‘xxx’?
怪我咯
怪我咯 2017-04-17 11:39:21
0
2
569

要求:
1. 只对指定的函数生效
2. 最好的编译器无关的(我用的是g++,如果不能实现编译器无关的,能让g++心满意足也足够了)
3. 不带来额外的运行时消耗
4. 给人带来的惊讶越小越好。(比如 signal = 0这样的做法就不推荐了)

求各种可行的有趣的quick but not dirty的解决方案。

怪我咯
怪我咯

走同样的路,发现不同的人生

répondre à tous(2)
左手右手慢动作

如果可能,请务必用正常方法消除 warning,真的多余就去掉吧

方法一:

void foo(int a) {
    (void)a;
    // ...
}

方法二:

#ifdef __GNUC__
#  define UNUSED(x) UNUSED_ ## x __attribute__((__unused__))
#else
#  define UNUSED(x) UNUSED_ ## x
#endif

void foo(int UNUSED(a)) {
    // ...
}

参考:http://stackoverflow.com/a/12891181

Peter_Zhu
void f(int) {
    // ...
}
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!