I have a function that examines an array and returns the index of the array if the probe succeeds.
In my code, for clarity, I made each type with respect to the index of the array a type_t .
What is the preferred way to maintain this clarity for this function? Should I take a pointer argument to an error variable and set this?
inline size_t lin_search(const double *pxa, const double x, const size_t idxlow, const size_t idxhigh) { for (size_t i = idxlow; i < idxhigh; i++) { if (pxa[i] <= x && pxa[i+1] > x) return i; } return -1;
Then I could use it as
index = linsearch(parray, x, 0, n - 1); if (index == -1) ... not found
luffe source share