c - 参数类型不兼容和类型冲突

标签 c prototype conflict incompatibility

#include <stdio.h>

void copy_arr(double, double, int);
void copy_ptr(double, double *, int);

int main()
{

    double source[5]={1.1,2.2,3.3,4.4,5.5}; 
    double target1[5]={0.0};
    double target2[5]={0.0};
    copy_arr(source, target1, 5);
    copy_ptr(source, target2, 5);
    return 0;
}

void copy_arr(double source[5],double target1[5],int arraysize)
{
    int count=0;
    puts("....copying using array notation.....");
    for(count=0;count<arraysize;count++)
        {
            target1[count]=source[count];
            printf("target 1 is : %d\t", target1[count]);
        }
}

double copy_ptr(double source[5],double *target2,int arraysize)
{
    int count=0;
    puts("....copying using pointer notation.....");
    for(count=0;count<arraysize;count++)
        {
            *(target2+count)=source[count];
            printf("target 2 is : %f\t", *target2);
        }
}

错误::

错误:“copy_arr”的参数 1 的类型不兼容 copy_arr(source, target1, 5);

错误:“copy_arr”的参数 2 的类型不兼容 copy_arr(source, target1, 5);

错误:“copy_ptr”的参数 1 的类型不兼容 copy_ptr(source, target2, 5);

错误:“copy_arr”的类型冲突 void copy_arr(double source[5],double target1[5],int arraysize)

错误:“copy_ptr”类型冲突 void copy_ptr(double source[5],double *target2,int arraysize)

我查了一下互联网,但一切都主要与原型(prototype)有关。我的在这里,但我仍然收到此错误!原因是什么?

最佳答案

您有以下原型(prototype):

void copy_arr(double, double, int);
void copy_ptr(double, double *, int);

然后你将它们声明为:

void copy_arr(double source[5],double target1[5],int arraysize)

double copy_ptr(double source[5],double *target2,int arraysize)

有问题。您的原型(prototype)采用单 double 作为参数,而不是 double 组。那么,在原型(prototype)中 copy_ptr 不返回任何内容,但在声明中返回 double。 将它们更改为:

void copy_arr(double[], double[], int);
void copy_ptr(double[], double *, int);
...
void copy_arr(double source[],double target1[],int arraysize)
void copy_ptr(double source[],double *target2,int arraysize)

关于c - 参数类型不兼容和类型冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25064710/

相关文章:

在标签上捕捉 WM_LBUTTONDOWN?

c - 如何从字符串中分离字母和整数?

javascript - 在构造函数*内部*分配原型(prototype)方法——为什么不呢?

c - 如何从linux库传递c中的参数

c - UDP校验和计算

javascript - 原型(prototype)框架或包含在js中

javascript - JS中数字原型(prototype)的自定义迭代器

java - maven重新打包模块解决依赖冲突

java - 为什么 java.lang.NoSuchMethodError occure 非常特定于环境或类加载器?

Laravel:模型名称和内置外观之间的冲突