I am wondering about this because of scope issues. For example, consider the code
typedef struct {
int x1;/*top*/
int x2;/*bottom*/
int id;
} sub
Yes, for a function declared to return a struct
, return
of such a struct will copy it (though the compiler is empowered to optimize the copy away, essentially in cases where it can prove the optimization is semantically innocuous, you can reason "as if" the copying was guaranteed).
However, since you did tag this as C++, not C, why not supply your struct
with a constructor, instead...? Seems clearer and more direct...!-)