(j3.2006) Frustrating consequence of F2003 allocation semantics
Craig Dedo CAPM
Tue Apr 14 11:41:48 EDT 2015
It appears to me that the only solution would be to place the reallocation
semantics of allocatable arrays into the hands of the developer, rather than being
specified by the standard. Thus, when declaring an allocatable array, the developer would
have the option of specifying whether reallocation was automatic or it needed to be done
explicitly. This would be another attribute. I don't have any particular syntax in mind.
We could possibly use Realloc_Auto for automatic reallocation and Realloc_Stable for
explicit reallocation only. Given the Fortran 2003 rules, Realloc_Auto would be the
default if neither was specified.
Another related need would be the provision of an inquiry intrinsic function
that would develop a list of the names of all pointers that point to a particular object.
A somewhat whimsical name could be, What_Pointers_are_Pointing_at_Me().
I'm not sure how difficult this second feature would be; it may be very
difficult or even impossible with some compiler architectures.
What do others think?
Please feel free to contact me at any time with any questions or concerns that
you may have. I am looking forward to hearing from you soon.
Craig T. Dedo, CAPM
17130 W. Burleigh Place
P. O. Box 423 Mobile Phone: (414) 412-5869
Brookfield, WI 53008-0423 E-mail: < <mailto:craig at ctdedo.com> craig at ctdedo.com>
Linked-In: <http://www.linkedin.com/in/craigdedo> http://www.linkedin.com/in/craigdedo
From: j3-bounces at mailman.j3-fortran.org [mailto:j3-bounces at mailman.j3-fortran.org] On
Behalf Of Tom Clune
Sent: Tuesday, April 14, 2015 09:05
Subject: (j3.2006) Frustrating consequence of F2003 allocation semantics
While in a debate with a client about being certain that we use appropriate flags to
activate F2003 allocation semantics, the client came back with this somewhat realistic
(1) We have a module variable declared as:
INTEGER, ALLOCATABLE, TARGET :: buffer(:)
(2) During initialization this array is allocated and provided initial values. Then, one
or more pointers is set to point at that array.
ptr => buffer
(3) Outside the module, various whole array assignments are done to buffer.
buffer = A
buffer = C
No issues so far. Now, however, suppose that there is a bug in the code, such that one of
the arrays on the RHS is of a _different_ shape than buffer. F2003 semantics will have
buffer reallocated to an appropriate shape for the copy. Previously one would expect
that proper use of debug flags would quickly localize the problem.
Unfortunately, F2003 semantics results in all pointers to buffer becoming invalid, while
buffer itself is "fine". We now have dangling pointers and a very difficult time
tracking down what went wrong - the symptoms are highly nonlocal. Debugging flags might
help us discover that the pointer is dangling, but they won't help much in tracking down
There are of course several stylistic ways to avoid using the F2003 automatic reallocation
in this scenario, but it would be difficult to enforce across an <ahem> 'diverse'
Does anyone have a good argument to push back on my client? Is anyone else concerned
about the implications of this example?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the J3