Lets imagine that we have function that should return two return values.
For instance we have some function that returns char*
and its length. Char is allocated within that particular function.
I can imagine following ways of doing that:
int foo(char **result); // Passing pointer to char*, returning int
char* bar(int *len); // Passing pointer to int, returning char*
struct char_and_len foobar(); // Returning struct that contains both values
Is there any other ways to implement multiple values and what's the most effective way to do that?
I'd really appreciate detailed explanation, considering performance, memory alignment or any other hidden C feature.