I have a function that returns a union, which the caller knows how to process. Is there an efficient 1-line way to return a union? What I do now:
typedef union { int i; char *s; double d; } FunnyResponse;
FunnyResponse myFunc () {
// Tedious:
FunnyResponse resp;
resp.d = 12.34;
return resp;
}
int main () {
printf ("It's this: %g\n", myFunc().d);
}
This compiles and runs however I'd like to have a single "return" line if possible. Any ideas?
union
? I don't see anything tedious. You will have to assign all of the fields you need to assign. In one line or in 100 lines. – Serous