这个变量的用法是什么在函数体中转换为void? [英] What's this usage of the variable cast to void in function body?

查看:141
本文介绍了这个变量的用法是什么在函数体中转换为void?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个函数的定义如下:

void printDebug(const char d1[]){(void)d1;}

它使用像这样:

printDebug("BLE_UART_EVENT");

我不明白其目的。它给我一个可调用的 char 数组的印象?

I don't understand its purpose. It gives me an impression of a callable char array?

推荐答案

不是调用 char 数组,它只是显式地将 char 数组转换为 void 。 (

It's not calling char array, it's just explicitly converting the char array to void. (And the evaluated result is discarded immediately.)

我认为这只是用来禁止编译器警告未使用的变量。

I think it's just used to prohibit the compiler warning of unused variables.

如果根本不使用参数,那么使它成为一个未命名的参数会更清楚。

If the parameter won't be used at all, it would be clearer to make it an unnamed parameter.

void printDebug(const char[]) {}

这篇关于这个变量的用法是什么在函数体中转换为void?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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