一、结构体拷贝传参
struct C
{
int a;
int b;
int c;
};
int test()
{
struct C st;
st.a=1;
st.b=2;
st.c=3;
printf("loccal of test ====\n");
printf("addr st = %x\n",(&st));
printf("addr st.a = %x\n",(&st.a));
printf("addr st.b = %x\n",(&st.b));
printf("addr st.c = %x\n",(&st.c));
return test4struct(st);
}
int test4struct(struct C st)
{
........
printf("addr st.c = %x\n",(&st.c));
........
}
结构体的存储,先定义的(a)存低地址,后定义的(b,c)存高地址
结构体参数压栈,先定义的后压栈
二、引用和常引用传参
int test4struct(struct C st)
{
........
test4structRef(st);
return 0;
}
int test4structRef(struct C &st)
{
printf("structRef test ====\n");
........
return test4conststructRef(st);
}
int test4conststructRef(const struct C &st)
{
...........
}
通过把对象地址压栈
三、大结构体做形参/数组拷贝
struct big
{
int a[10];
int b[10];
int c[10];
};
int test4conststructRef(const struct C &st)
{
............
struct big b;
b.a[2]=2;
b.b[3]=3;
b.c[4]=4;
return test4bigstruct(b);
}
int test4bigstruct(struct big b)
{
char c[13]={"aaaaaaaa"};
......
printf("addr big.a = %x\n",(&b.a));
printf("addr big.b = %x\n",(&b.b));
......
abort();
return 0;
}