admin管理员组文章数量:1122832
The following code is working as expected, unless I'm using -fmax-stack-var-size=0
with gfortran 12.3, 13.3 or 14.2.1. In which case, the function returns an empty string.
program test_clean_str
implicit none
character(len=100) :: input_str
character(len=:), allocatable :: result_str
input_str = ' Test String '
result_str = clean_str(input_str)
print *, 'Result:-', result_str,"-"
contains
function clean_str(str_in) result(str_out)
implicit none
character(len=*), intent(in) :: str_in
character(len=:), allocatable :: str_out
str_out = trim(str_in)
print*,"-",str_out,"-"
end function clean_str
end program test_clean_str
This change of behavior does not occur if the function is rewritten as a subroutine or if I'm working with integer arrays instead of character string.
Does this change of behavior is to be expected ?
Edit: remove the mention to ifort and ifx as they are not concerned, and add precision about the concerned version of gfortran
本文标签: fortranFunction wrongly returning empty character string if allocated on the heapStack Overflow
版权声明:本文标题:fortran - Function wrongly returning empty character string if allocated on the heap - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736310119a1934262.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论