I have a function returning a named struct consisting of two ints, as follows:
struct myStruct {int i; int j;};
myStruct myFunction(int myArg){
switch (myArg) {
case 0: return {1,2};
case 1: return {2,3};
default: return {4,5};
}
}
I want to be able to return the appropriately initialised struct from my switch statement. I can do this by declaring a named struct and initialising it, then returning the named struct, but it would be cleaner if I could have the compiler created anonymous structs for me as in my example above - which does not compile. Can this be made to work (legitimately)? Or what is the cleanest way to achieve my goal?