我怎样才能抑制“未使用的参数"?C中的警告? [英] How can I suppress "unused parameter" warnings in C?

查看:35
本文介绍了我怎样才能抑制“未使用的参数"?C中的警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如:

Bool NullFunc(const struct timespec *when, const char *who)
{
   return TRUE;
}

在 C++ 中,我能够在参数周围添加 /*...*/ 注释.但当然不是在 C 中,它给了我错误:

In C++ I was able to put a /*...*/ comment around the parameters. But not in C of course, where it gives me the error:

错误:省略了参数名称

推荐答案

我通常这样写宏:

#define UNUSED(x) (void)(x)

您可以将此宏用于所有未使用的参数.(请注意,这适用于任何编译器.)

You can use this macro for all your unused parameters. (Note that this works on any compiler.)

例如:

void f(int x) {
    UNUSED(x);
    ...
}

这篇关于我怎样才能抑制“未使用的参数"?C中的警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆