In C component selection, what is the benefit of structure-returning function? for example:
struct S {
int a, b;
} x;
Why is it that I can assign the above struct as a function as shown below, Is there any benefit of doing this?
extern struct S f(); /* Why is this neccesary? */
x = f(); /* Is this accurate */
Open my eyes on this guys.
It’s just a function that happens to return a
struct. There’s nothing more to it than that. You wouldn’t be surprised to see a function return anint, why be surprised when one returns a struct?As an aside, the
externis superfluous here because that is the default storage class for functions.