Reputation: 2375
I'm sure this is an easy answer for someone with experience with pointers in c, but I am struggling at the moment to see my error. I get a warning that the return call from a function makes a pointer from integer, even though the return type of the function is a pointer. And get the error that the function has conflicting types. Here is the code, I have removed the body of the function and I still get the error and warning.
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){
}
Upvotes: 0
Views: 1687
Reputation: 75150
You need to declare your function merge
above merge_sort
; when the compiler sees a call to a function that hasn't been declared yet, it automatically assumes it returns an 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){
}
Upvotes: 7