I’d like to understand what happens when passing an implicit array of characters (I don’t know if it is the proper name) to a function. In the following code for instance, the first call to func1 behaves as expected and prints all elements of test_array.
The second call, however, results in a core dumped with SIGABRT, and prints the following:
I ran your program with gfortran version 12.2.0 and Intel oneAPI Fortran, ifort version 2021.9.0 and ifx version 2023.1.0: the first version fails as you indicated, but the versions built with Intel work as expected. I see no problem with the source code, so I definitely think that this is a bug in gfortran. You may want to report it.
The code compiles and runs with gfortran 13.1.0, but the output looks odd. I changed the write statement to
print *, 'len=', len(array), ' ARRAY = ', array
The first call prints the value of 256, while the second call prints the value of 18. The subsequent printed strings reflect those two len values.
With nagfor, both calls print the value of 256, which to my eye looks correct.
If I replace all of the occurrences of trim(prefix) with simply prefix, then both compilers print the same output as they did before. I don’t see any reason why the function argument should be trimmed or the len() value changed. Am I missing something here, or is this a gfortran bug?