
2008/5/16 Noah Roberts
Nevin ":-]" Liber wrote:
2008/5/16 Noah Roberts
mailto:roberts.noah@gmail.com>: I don't like this idea. You are creating a dependency on the fact that the called function will NOT keep a copy
Suppose I had the function: void foo(int const* p) { if (p) std::cout << *p << std::endl; } It is perfectly legal to call it as: void bar() { int i(2); foo(&i); } int main() { bar(); bar(); } Now, if we let foo squirrel away a copy of p, as in: void foo(int const* p) { static int const* pp; if (p && pp) std::cout << *pp << ' ' << *p << std::endl; pp = p; } The program is now broken, since it is illegal to dereference pp during the second call to foo(), yet foo has no way of knowing that. What should the interface to foo() be such that it doesn't break whether or not foo() keeps a copy of p? -- Nevin ":-)" Liber mailto:nevin@eviloverlord.com (847) 691-1404