假定buffer是由包括一个阵列在内的若干成员组成的结构。
如果与通常的最佳旗帜相匹配,那么,如果有人期望使用这两种代码,会有什么区别?
buffer buf;
for (int i = 0; i < BIG_ENOUGH_NUMBER; i++) {
init(huge_file, i, &buf);
}
// buf is not used afterward
...
void init(FILE* f, int i, buffer* b) {
... // b is filled using f, according to i
do_something(b);
}
v
for (int i = 0; i < BIG_ENOUGH_NUMBER; i++) {
init(huge_file, i);
}
...
void init(FILE* f, int i) {
buffer buf;
... // buf is filled from scratch using f, according to i
do_something(&buf);
}