J
jacob navia
In the new "templated" form of the containers library I have now that
all data retrieving functions return the data directly:
int (*GetElement)(intList *l,size_t idx);
The problem is that it is not possible to return an error
with this configuration: Since the return value is an
int, any error code could be actually some data!!
The solution is to return a pointer to the data and NULL
if there is an error, as the other functions of the library do.
But this doesn't look great with the syntax viewed from the
user's side:
Instead of:
int m = iintList.GetElement(mylist,23);
you should write:
int m = *iintList.GetElement(myList,23);
risking a core dump if there is a NULL return.
Obviously if the list has only 20 elements, the core dump
is actually a good thing since it will show you the error immediately.
Before returning, the "GetElement" API calls the error function
and will return ONLY IF the error function returns.
I was relying in that as error handling, and just returning zero...
After some reflection I am convinced now that this would be a bad design
decision.
What do you think?
jacob
all data retrieving functions return the data directly:
int (*GetElement)(intList *l,size_t idx);
The problem is that it is not possible to return an error
with this configuration: Since the return value is an
int, any error code could be actually some data!!
The solution is to return a pointer to the data and NULL
if there is an error, as the other functions of the library do.
But this doesn't look great with the syntax viewed from the
user's side:
Instead of:
int m = iintList.GetElement(mylist,23);
you should write:
int m = *iintList.GetElement(myList,23);
risking a core dump if there is a NULL return.
Obviously if the list has only 20 elements, the core dump
is actually a good thing since it will show you the error immediately.
Before returning, the "GetElement" API calls the error function
and will return ONLY IF the error function returns.
I was relying in that as error handling, and just returning zero...
After some reflection I am convinced now that this would be a bad design
decision.
What do you think?
jacob