------- Comment #6 from michael dot baudin at gmail dot com 2008-04-18 15:07 ------- Subject: Re: Recursive function with allocatable array
I used the -fdump-tree-original option to compare the version produced on this source code with allocatable and pointer. Only the allocatable contains the following statements : static struct t_type subpattern = {}; subpattern.chars.data = 0B; I understand that the statement " subpattern.chars.data = 0B;" allows to free the array when it goes out of scope, as the standard says about allocatable arrays (which explains why it is not in the pointer version) : if (subpattern.chars.data != 0B) { __builtin_free (subpattern.chars.data); } subpattern.chars.data = 0B; The statement "static struct t_type subpattern = {};", which is not in the pointer version, is the cause of the problem so that the solution is to remove it : at second call, the array has been initialiazed to null, and because it is static, it memory is still deallocated on recursive calls. An allocatable array in a recursive subroutine should not be static (in fortran, that means having the SAVE attribute), isn't it ? Am I right ? Best regards, Michaƫl -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35959