【发布时间】:2020-08-07 18:10:18
【问题描述】:
我看到了这段代码。但不知道目的是什么。
void a()
{
static const char *string = "STRING";
...
(void)string; // <---- What the purpose of the line is?
...
}
【问题讨论】:
我看到了这段代码。但不知道目的是什么。
void a()
{
static const char *string = "STRING";
...
(void)string; // <---- What the purpose of the line is?
...
}
【问题讨论】:
(void) 在这样的变量之前创建一个空表达式,并用于消除有关程序未使用变量的警告。
在这种特定情况下,最好简单地注释掉变量声明。
【讨论】:
volatile。因为本地 const 变量往往最终会出现在堆栈中,因此更容易被优化出来。