In Go they often do the whole (err, val)
thing, in Rust they do similar (+ syntactic sugar).
I'm not sure if I should have this type of struct
for each of my types:
typedef struct {
int status;
char *const *c_str_arr;
size_t size;
} StatusAndArrayCStrArray;
extern void cleanup_struct_cstr_array(StatusAndArrayCStrArray *status_and_array) {
if (status_and_array->c_str_arr != NULL) {
free((void *) status_and_array->c_str_arr);
status_and_array->size = 0;
}
}
static const StatusAndArrayCStrArray statusAndArrayCStrArrayNull = {
EXIT_FAILURE, NULL, 0
};
That seems to be a lot of wasted space. Maybe a union
would be better? - I've also seen some perror
stuff so maybe I'm meant to set an error code and return the value, and then first check if there is an error the perror-way else return the value?
Related: Error handling in C code