【发布时间】:2019-08-24 15:18:42
【问题描述】:
请考虑以下代码:
void bar(Thing* thing) {
some_buffer[some_index++] = *thing;
}
void foo(void) {
Thing thing;
bar(&thing);
}
some_buffer[some_index++] = *thing; 是否创建原始thing 的副本?
就内存而言,这段代码是否保证安全?因为foo 中的thing 在foo 退出时显然已经死了。
【问题讨论】:
-
代码错误,因为没有
Thing、some_buffer或some_index的定义...