我确信对于有c指针经验的人来说,这是一个简单的答案,但我现在正在努力查看我的错误。我收到一个警告,即函数的返回调用会产生一个来自整数的指针,即使该函数的返回类型是指针。并获得函数具有冲突类型的错误。这是代码,我删除了函数体,我仍然得到错误和警告。
long long *merge_sort(long long * arr, int size){
// Arrays shorter than 1 are already sorted
if(size > 1){
int middle = size / 2, i;
long long *left, *right;
left = arr;
right = arr + middle;
left = merge_sort(left, middle);
right = merge_sort(right, size-middle);
return merge(left,right);
}else { return arr; }
}
long long *merge(long long * left, long long * right){
}
答案 0 :(得分:7)
您需要在merge
之上声明您的函数merge_sort
;当编译器看到对尚未声明的函数的调用时,它会自动假定它返回int
:
// forward declaration
long long *merge(long long * left, long long * right);
long long *merge_sort(long long * arr, int size){
// Arrays shorter than 1 are already sorted
if(size > 1){
int middle = size / 2, i;
long long *left, *right;
left = arr;
right = arr + middle;
left = merge_sort(left, middle);
right = merge_sort(right, size-middle);
return merge(left,right);
}else { return arr; }
}
long long *merge(long long * left, long long * right){
}