J3/05-217
Date: July 09, 2005
To: J3
From: Aleksandar Donev
Subject: Adding TYPE_SOURCE to ALLOCATE (was MOLD)
References: Rewrite of repository item J3-034, from J3/05-157, still in
undecided state after Delft meeting.
Status: For Consideration
Basic Functionality:
A TYPE_SOURCE argument should be added to ALLOCATE similar to the SOURCE
argument, which would only give the type of the allocated data, but not
the contents. This would allow one to allocate an array of a certain
type given only a scalar of that type, without having access to the
type itself. This allows memory management to be implemented by base
classes and later simply inherited and reused. It also allows one to
implement memory-management for generic endogenous data structures like
bounded stacks.
Example:
Given:
CLASS(*), POINTER :: mold
CLASS(*), DIMENSION(:), ALLOCATABLE :: storage
ALLOCATE(REAL::mold)
the statement:
ALLOCATE(storage(100), type_source=mold)
allocates an array of REALs, exactly equivalent to:
ALLOCATE(REAL::storage(100))
History:
At the Delft meeting, during the discussion of my proposal to add a MOLD
keyword to ALLOCATE, it was concluded that the name MOLD is misleading
since only the dynamic type of the MOLD is used, but not the shape
(important for ALLOCATABLE components, for example). Also, some people
expressed preference to specify this in the same location where we can
currently specify a type for the allocation, namely the .
This proposal addresses the first objection and tries to model in
parallel to the existing SOURCE, rather than to the . If it
is decided to move the proposed feature to the instead, new
syntax will need to be invented, for example,
ALLOCATE(TYPE(MOLD=)::)
However, I believe the functionality itself should not be modified, in
particular, the interpretation of the statement should be as if the
dynamic type of were specified in .
Rationale:
This has been given elsewhere.
Detailed Specification:
Add a TYPE_SOURCE keyword to the ALLOCATE statement, to determine the
type of
the allocated object, just like SOURCE, but using default initialization
for the value of the allocated object. Also allow the type-source to be
a
scalar even if the allocation is for a higher-rank array.
These are edits I have prepared earlier in reference to J3-007R3. They
illustrate the basic ideas:
108: 15+ Add:
or TYPE_SOURCE =
109: 4+ Add:
is
109: 6 Replace:
", either , TYPE_SOURCE=, or SOURCE= shall appear"
109: 10 do the same as for 109:6
109: 19+ Add constraint:
(Cxxx) Both SOURCE= and TYPE_SOURCE= shall not appear.
109: 20 Add:
"IF SOURCE= or TYPE_SOURCE= appears," and
"with or "
109: 23 Add:
"and or "
109: 33 Add:
"if a or "
109: 34 Add:
"the or "
110:10+ Add:
"If TYPE_SOURCE= appears, default initialization is performed for
for the dynamic type of . If the
value
of a nondeferred nonkind type parameter of is
different from the value of the corresponding type parameter of
, an error condition occurs."
History: Rewrite of repository item J3-034, from J3/05-157, still in
undecided state after Delft meeting.