(j3.2006) Chaining type-bound procedure references
Rafik Zurob
rzurob
Fri May 2 01:00:31 EDT 2014
Hello
While I use this feature extensively in my C++ programs, I (personally)
strongly oppose it in today's Fortran. C++ can get away with
x.foo().bar() because inlining is part of the language and the definitions
of inline member functions appear in the same translation unit as the
call. That's not the case in Fortran.
val = x%foo()%bar()
would require a temp pointer
temp_ptr_dscr => x%foo()
val = temp_ptr_dscr%bar()
The most common usage would be for foo to be written as a module procedure
and to be accessed via use-association. i.e. It's going to be in a
separate compilation unit and require inter-procedural analysis to inline.
It's a similar situation to ASSOCIATE, but ASSOCIATE encourages the user
to reuse the temp since the temp is really the associate name. Allowing
the x%foo()%bar() syntax encourages many references to the same pointer
function, thus resulting in many temps (and many pointer assignments).
Even if you forget about inlining, you would expect the compiler to
attempt to reuse the temp pointers / get rid of multiple calls to foo.
That's not easy, even if you mandate that pointer functions like foo must
be pure. Note that Fortran has the notion of pure, but does not have the
notion of const functions that are pure and don't read any use-associated
or host-associated data.
Regards
Rafik
PS These concerns are also why I don't like F2008's pointer function refs
as vars feature.
More information about the J3
mailing list