为什么将未使用的函数参数值强制转换为 void? [英] Why cast an unused function parameter value to void?

查看:18
本文介绍了为什么将未使用的函数参数值强制转换为 void?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一些 C 项目中,我见过这样的代码:

In some C project, I have seen this code:

static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {
    (void)ud;
    (void)osize;
    /* some code not using `ud` or `osize` */
    return ptr;
}

这两次对 void 的强制转换是否有任何用途?

Do the two casts to void serve any purpose?

推荐答案

这是为了避免编译器因为某些参数未使用而发出警告.

It is there to avoid warnings from the compiler because some parameters are unused.

这篇关于为什么将未使用的函数参数值强制转换为 void?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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