gpt4 book ai didi

c - 为什么将未使用的函数参数值转换为 void?

转载 作者:行者123 更新时间:2023-11-30 16:31:04 25 4
gpt4 key购买 nike

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

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 转换有什么作用吗?

最佳答案

它是为了避免编译器发出警告,因为某些参数未使用。

关于c - 为什么将未使用的函数参数值转换为 void?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50805044/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com