【问题标题】:Incompatible type for argument and conflicting types参数和冲突类型的不兼容类型
【发布时间】:2014-07-31 16:53:23
【问题描述】:
#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)

我在网上查了资料,但大部分都是关于原型的。我的在这里,但我仍然收到此错误!是什么原因?

【问题讨论】:

  • 您有问题吗?
  • 我想问题是:你能帮我解决错误吗? :)
  • ...主要是关于原型。 检查原型。例如,doubledouble[5] 的类型不同。
  • 谢谢@John C 现在只有我知道他们不一样哈哈!
  • 我的意思不是进攻性的,只是认为轻轻一推就能让你重新定位。你几乎总是可以为它的原型复制一个函数的签名行,因为名称被忽略了。

标签: c prototype conflict incompatibility


【解决方案1】:

你有以下原型:

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)

有问题。您的原型将单个双打作为参数,而不是双打数组。然后,在原型中 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)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-11-19
    • 2015-10-21
    • 2020-05-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-07
    相关资源
    最近更新 更多