4 ms·
A common way to solve that is to have a function argument point to a place where you want the result to end up, and always return FOO_ERROR or FOO_OK. i.e.,
by sebcat 11y ago
A common way to solve that is to have a function argument point to a place where you want the result to end up, and always return FOO_ERROR or FOO_OK.
i.e.,
int foo_new(foo_t **res);
int foo_mutate_copy(foo_t *foo, bar_t *bar, foo_t **new_foo);
Instead of
foo_t *foo_new(); // returns NULL on failure
foo_t *foo_mutate_copy(foo_t *foo, bar_t *bar); // returns NULL on failure
I also like the Go way, just thought this way of doing things in C should be mentioned in the thread.
- voidlogic 11y ago>using up your only return value and having to take pointer arguments when you would rather not. I specifically mention the C way of doing things- but use you demonstrate it above. I was suggesting the Go way is superior.