我对此感到疑惑是因为范围问题
typedef struct {
int x1;/*top*/
int x2;/*bottom*/
int id;
} subline_t;
subline_t subline(int x1, int x2, int id) {
subline_t t = { x1, x2, id };
return t;
}
int main(){
subline_t line = subline(0,0,0); //is line garbage or isn't it? the reference
//to subline_t t goes out of scope, so the only way this wouldn't be garbage
//is if return copies
}
所以我的问题是 return 语句会一直复制吗?在这种情况下,它似乎工作,所以我相信,返回确实复制。如果它确实复制了,它会在每种情况下都复制吗?