I am writing a library for C, and one function can return either a string (char *
), an integer or a double. Next to that, the length of the string is unknown. I really don't know how to deal with this problem. I thought about using pointers as arguments to the function but that is really messy.
Can anyone give me a solution, and maybe some short sample code? Thanks.
Edit
What about a void pointer as return type, and a pointer to the size of the returned value as argument:
void* func(int x, int y, int *size) { ... }
/* or */
void* func(int x, int y, int &size) { ... }
/* always confused about them ): */
?