You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

gfortran指定-fmax-stack-var-size=0时,函数错误返回空字符串

gfortran中-fmax-stack-var-size=0导致函数返回空字符串是否符合预期?

以下Fortran代码在常规编译运行时结果符合预期,但在gfortran 12.3、13.3或14.2.1版本中,使用编译选项-fmax-stack-var-size=0时,clean_str函数会返回空字符串:

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

存在以下对比情况:

  • 将该函数改写为子程序时,不会出现此异常行为
  • 使用整数数组而非字符串作为返回对象时,也不会出现此行为变化

请问该行为变化是否属于预期情况?

内容的提问来源于stack exchange,提问作者pums974

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 05:27:06