On Tue, Dec 17, 2013 at 7:01 PM, Chris Angelico <ros...@gmail.com> wrote: > On Wed, Dec 18, 2013 at 1:33 PM, Devin Jeanpierre > <jeanpierr...@gmail.com> wrote: >> Yes you do. Lifetimes are hard, because you need to malloc a lot, and >> there is no defined lifetime for pointers -- they could last for just >> the lifetime of a stack frame, or until the end of the program, or >> anywhere in-between, and it's impossible to know for sure, and if you >> get it wrong your program crashes. So there's all these conventions >> you have to come up with like "borrowing" and "owning", but they >> aren't compiler-enforced, so you still have to figure it out, and you >> will get it wrong. Successors like C++ mitigate these issues with >> destructors (allowing heap-allocated stuff to be tied to the lifetime >> of a stack), and smart pointers and so on. > > Wrong. A pointer is a scalar value, usually some kind of integer, and > its lifetime is the same as any other scalar.
The duration of a pointer's validity is far more interesting, and that is why it is the primary meaning of the term "pointer lifetime". Also, it's obviously what I meant. > Heap memory's lifetime > is also very simple: it lasts until freed. Sometimes simple things are hard to use correctly. I only said it was hard, not complicated. -- Devin -- https://mail.python.org/mailman/listinfo/python-list