相关疑难解决方法(0)

如何在C中抑制"未使用的参数"警告?

例如:

Bool NullFunc(const struct timespec *when, const char *who)
{
   return TRUE;
}
Run Code Online (Sandbox Code Playgroud)

在C++中,我能够对/*...*/参数进行评论.但当然不是在C中,它给了我错误error: parameter name omitted.

c gcc gcc-warning

195
推荐指数
10
解决办法
15万
查看次数

参数名称省略,C++ vs C.

在C++中,我倾向于在某些情况下省略参数的名称.但是在C中,当我省略参数的名字时出错了.

这是代码:

void foo(int);  //forward-decl, it's OK to omit the parameter's name, in both C++ and C

int main()
{
    foo(0);
    return 0;
}

void foo(int)  //definition in C, it cannot compile with gcc
{
    printf("in foo\n");
}

void foo(int)  //definition in C++, it can compile with g++
{
    cout << "in foo" << endl;
}
Run Code Online (Sandbox Code Playgroud)

这是为什么?我不能省略C函数定义中的参数名称吗?

c c++ compilation

39
推荐指数
3
解决办法
2万
查看次数

标签 统计

c ×2

c++ ×1

compilation ×1

gcc ×1

gcc-warning ×1