c - 我用相同的输出声明了相同的函数
问题描述
在 C 上编程,奇怪的是我将 void edges(...) 输出声明为 void 并在 int main(void) 下执行相同的操作,但是,我收到一条错误消息,说明我正在声明不同的输出。我想知道这有什么问题?
#include <math.h>
#include <stdio.h>
#include <cs50.h>
typedef struct{
int rgbtBlue;
int rgbtGreen;
int rgbtRed;
}
RGBTRIPLE;
int make_image_array(int);
void edges(int, int, RGBTRIPLE);
int main(void){
edges(height, width, image[height][width]);
}
void edges(int height, int width, RGBTRIPLE image[height][width])
{}
终端上的错误消息显示功能边缘的类型冲突???
解决方案
这个故事的简短版本是——你的编译器是对的......
如果您查看原型:
void edges(int, int, RGBTRIPLE);
它需要三个参数,一个int
,,int
和anonymous struct RGBTRIPLE
。但是,当您定义函数时,您定义了一个 2D 数组RGBTRIPLE
,例如
void edges(int height, int width, RGBTRIPLE image[height][width])
{}
看到不同?RGBTRIPLE
原型和RGBTRIPLE[height][width]
定义中的单曲。
修复原型的最简单方法是提供可用作 2D VLA 所需尺寸的命名变量,例如
void edges(int a, int b, RGBTRIPLE[a][b]);
更好的是,完全取消原型并简单地edges
在上面定义main()
——这样你就消除了任何不匹配的机会。
推荐阅读
- python - Python Django Celery,终止正在运行的任务不起作用
- php - 如何在 wordpress 帖子中列出存储在谷歌云存储桶中的文件?
- python-3.x - 如何在 lambda 中为 python3 赋值?
- flutter - Flutter Sembast 插入或更新
- php - Laravel 作业队列调度现在不会像往常一样失败
- javascript - 如何检查 x 和 y 是否在对象中?
- python - python中的输出与python3不同(相同的脚本)
- c++ - 在其特征向量上投影点云
- ionic-framework - 运行“npx cap add android”时出现错误 -4048
- c# - 如何正确重命名语法树中的所有变量