I have a simple question (?).
I am writing a simple program that has several functions that look like this.
float foo (float* m,size_t n){
float result;
return result / n;
}
I have a couple of questions about this, with no intention of renewing some kind of holy war.
Should I add a health check on n? If so, how can I tell the caller?
The return -1looks weird over the floats;
float foo(float *m,size_t n){
if (n == 0) return -1f
...
}
Another option is the out parameter
float foo(float *m,size_t n, int *error){
if (n==0){
*error = 1;
return 0f;
}
...
}
Update
This is a kind of toy program, just trying to practice something. This question stems from this fact. Perhaps I should rephrase "how to handle errors without exceptions (OOP)."
n , .
?
.