c - 当第一个参数是结构类型时,C 中的函数声明问题
问题描述
我正在使用由其他人编写的用于某种目的的 C 代码。编译程序时:
警告:函数“shine”的隐式声明 [-Wimplicit-function-declaration
我在下面给出部分代码:
struct attribute
{
int type, symb;
float lower, upper;
} examples[MaxExs][MaxAtts];
下面是在 func1() 内部调用 Shine() 的代码。
int func1()
{
int e, r, nstrule;
float lwstdist;
...
shine(examples[e], &nstrule, &lwstdist, e);
...
}
下面是shine() 的函数定义。
int shine(ex, nstrule, lwstdist, leftout)
struct attribute ex[];
int *nstrule, leftout;
float *lwstdist;
{
...
}
我只想删除该警告。所以我想在代码的开头声明它。我尝试使用:
int shine(xxx, int*, float*, int);
我不知道我做的是否正确以及用什么来代替 xxx。我是C的新手。所以我无法弄清楚。如果我能获得一些材料来完成这个特定的事情,那么除了这个帮助之外,这将是一个很大的帮助。
解决方案
您需要放置一个前向声明struct attribute
。
struct attribute;
int shine(struct attribute[], int*, float*, int);
顺便提一句。未命名的函数参数不是标准的 C。尽管许多编译器都接受它,因为它在 C++ 中是允许的并且实现起来很简单。
此功能将添加到即将发布的 C23 标准中的 C 中。
推荐阅读
- r - Plotly(R)中关于“标记”的错误消息
- r - 如何合并R中具有不同列名的两个数据集?
- ios - 为什么 UIAccessibilityNotification 不转向正确的论点?
- powershell - 使用 GitHub 包注册表作为 PowerShell 包存储库
- quarkus - Quarkus 异常处理程序
- java - 在 Chrome 中运行 selenium 测试用例时无法从弹出框加载扩展
- node.js - Mongodb服务器选择超时与nginx,nodejs
- docker - 有没有办法查看完整的 Docker 映像继承?
- swift - 是否可以使用 SwiftUI 将键盘上的“返回”键更改为“完成”?
- c# - 用重复的代码重构静态类c#