This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: Functions returning pointers
Tobias Schlüter wrote:
> Unfortunately, it doesn't work this way. Nothing from the tree dumps strikes
> me as an obvious mistake right now, but I'll see if I can find out what goes
> wrong.
>
Turning on optimization changed that. Consider:
character*5, target :: c,e
c = "Hallo"
e = g()
print *,e
contains
function g()
character(5), pointer :: g
g => c
end function g
end
The function g gets compiled to this:
(t03.original)
g (__result, .__result)
{
__result = (int1[1 .. 5] * &)&c;
Apparently, this statement only looks meaningful, the function is "optimized" to:
(t59.optimized)
;; Function g (g.435)
g (__result, .__result)
{
int1 * c.2;
<bb 0>:
return;
}
I.e. the compiler decides that the statement has no effect. Maybe it should be
*__result = ... in the original dump?
- Tobi