【发布时间】:2016-04-29 03:07:09
【问题描述】:
假设我有一个函数,它接受一个结构数组,定义如下:
void Foo(struct MyStruct *s, int count) {
for (int i = 0; i < count; ++i) {
// Do something with s[i]
}
}
是否保证以下两个 sn-ps 的行为方式相同?
struct MyStruct s;
s.x = 0;
s.y = 0;
Foo(&s, 1);
对比
struct MyStruct s[1]; // stack-allocated array of size 1
s[0].x = 0;
s[0].y = 0;
Foo(s, 1);
【问题讨论】:
-
godbolt.org/g/3iq38U 你可以看到他们生成了相同的机器码