|Strong/weak pointers firstname.lastname@example.org (Michiel Helvensteijn) (2008-09-01)|
|Re: Strong/weak pointers email@example.com (lican) (2008-09-01)|
|Re: Strong/weak pointers Jan.Vorbrueggen@thomson.net (=?ISO-8859-15?Q?Jan_Vorbr=FCggen?=) (2008-09-02)|
|Re: Strong/weak pointers firstname.lastname@example.org (Marco van de Voort) (2008-09-02)|
|Re: Strong/weak pointers email@example.com (2008-09-02)|
|Re: Strong/weak pointers firstname.lastname@example.org (Dmitry A. Kazakov) (2008-09-02)|
|Re: Strong/weak pointers email@example.com (Armel) (2008-09-03)|
|Re: Strong/weak pointers firstname.lastname@example.org (glen herrmannsfeldt) (2008-09-03)|
|Re: Strong/weak pointers email@example.com (JW) (2008-09-03)|
|[2 later articles]|
|Date:||Tue, 02 Sep 2008 09:52:50 +0200|
|Organization:||Guest of France Telecom's news reading service|
|Posted-Date:||03 Sep 2008 05:17:53 EDT|
You might take Fortran in its current incarnation, 2003, or the previous
one, 95 with the so-called ALLOCATABLES Technical Report (TR) - as
precedent. In Fortran, what you call strong pointers are ALLOCATABLE
variables. Barring a compiler or run-time bug, they cannot leak memory,
and they always are in a deterministic state. Your weak pointers are
called POINTER variables, and they have indeed all the problems you
> In particular, can you think of any good use-cases for weak pointers?
The TR mentioned above removed a lot of required previous POINTER usage
from Fortran 95, but that was because ALLOCATABLEs (before the TR) were
quite limiteed in use (for instance, the allocatable property could not
be passed across calls). There remain two major reason why they are in
- You need a POINTER to a structure to build linked lists and similar
- Fortran supports multi-dimensional arrays as first-class citizens. A
POINTER can be defined to point to a subset of an array, e.g., a slice
along some dimension. This is a very useful facility than cannot be
easily provided in a different way.
For the historical reason mentioned above, POINTERs have some properties
that they need not have for just thoss application. For instance, you
can allocate and deallocate memory through a POINTER.
As always in Fortran, it's the programmer's responsibility to get
certain things right, e.g., to track POINTER-allocated memory properly.
That's why they should only be used in restricted circumstances. On the
other hand, the language design gives certain guarantees, as mentioned
above, about ALLOCATABLEs that the programmer can rely on. The
combination makes it unnecessary for the compiler and run-time to use
reference counting on dynmically allocated memory.
Return to the
Search the comp.compilers archives again.