I was writing a binary search function:
int binsearch(int seq, int start, int end, int key)
int len = end - start + 1;
int mid = (start + end) / 2;
if (len <= 0)
else if (key == seq[mid])
else if (key < seq[mid])
binsearch(seq, start, mid - 1, key);
binsearch(seq, mid + 1, end, key);
The behaviour of your program is undefined; you must explicitly
return a value on all control paths.
A kind compiler will warn you of this; gcc certainly does if you set an appropriate warning level.
I believe that the fix in your case is to write
return before your
(The only exception to this is
int main(...) where the compiler must introduce an implicit
return 0; if it's missing).