- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I was just wondering how does the compiler treat associate block when the associate-name "points" to a function results as in:
[fortran] associate( Var1 => This%Fun1(a,b) )
Var2 = This%Fun2(c,d,Var1)
end associate[/fortran]
My 2 questions are
- Does the compiler treats this by simply replacing the associated name (here "Var1") by the selector (here "This%Fun1(a,b)") inside the associated block ? If so, can associate blocks be seen as a sort of inlining for variable instead of procedures.
- Does associate blocks really have no effect on performance ?
Thanks.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I think the real question to ask is with this code:
[fortran]
type(someType), pointer :: This
...
associate( Var1 => This%Fun1(a,b) )
...
This => That
Var2 = This%Fun2(c,d,Var1)
end associate
[/fortran]
What value for "This" does Var1 use? Prior "This" or subsequent (current) "This"?
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ASSOCIATE is not like macro expansion. Probably the best way to think of it is like a pointer that points to the selector expression. There are some limitations as to what you can do inside the block. In the first case shown, the function is called when the block is entered and its result assigned to the newly created variable var1. Inside the block, var1 is used like a normal variable - there's no inlining going on.
It gets more interesting when you use something like:
associate (var1 => a%b(3))
where b is also a derived type. You can, inside the block, do something like var1%c.
In Jim's example, it uses the value of This at entry to the block.
As for performance impact, I would say it is minimal to nonexistent.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the answer.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page