Suppose I have a function that returns an instance of a struct
with the following declaration:
struct data API(void)
;
Suppose also that there is a chance for the function to fail with an error during the execution. What is the best way to indicate that an error occurred?
A solution that comes to mind is to create a structure that nests the actual data structure along with an exit status, like so:
struct result {
signed int exit;
struct data;
}
and change the function declaration to the following:
struct result API(void);
Is there a better way to do this? I am well aware of the de-facto standard of writing to a structure pointed to by an argument, e.g. int API(struct data *location)
.