struct s1 { int a; int b; };
struct s2 { int a; int b; };
struct s2 test(void) {
struct s1 s = { 1, 2 };
return s; // incompatible types
}
In the above code, can I return s without creating a new struct s2 variable and populating it with s‘s values? It is guaranteed that struct s1 will always be identical to struct s2.
You can’t return the struct directly, but you can avoid
creating a separate variable in your source code by using a compound literal,
which is a feature of C99.