I even didn't know that CHARACTER(*) could be used in ALLOCATE statement...
If the above interpretation is right, does this possibly belong to
an "undefined behavior" (processor-dependent) category...?
# People in JISCmail seems to assume the use of character(*) in allocate() is OK.
https://www.jiscmail.ac.uk/cgi-bin/webadmin?A0=comp-fortran-90
---
Some code I have tried:
module test_m
implicit none
contains
subroutine sub( s )
character(*), allocatable :: s
print *
print *, "sub: len(s) (upon entry) =", len( s )
if ( allocated( s ) ) then
print *, "sub: s = ", s, " len =", len(s)
else
print *, "sub: allocating s"
allocate( character(*) :: s )
s = "hello-from-sub"
endif
print *, "sub: s (upon exit) = ", s
print *
endsubroutine
endmodule
program main
use test_m
implicit none
character(10), allocatable :: s1, s2
allocate( s1 )
s1 = "hi"
print *, "main: s1 (before call) = ", s1
call sub( s1 )
print *, "main: s1 (after call) = ", s1
call sub( s2 )
print *, "main: s2 (after call) = ", s2
!! gfort-7.2 : ICE (on OSX10.11, installed via homebrew)
!! pgi-2017.4, oracle12.5, ifort16 : gives the following output
end
main: s1 (before call) = hi
sub: len(s) (upon entry) = 10
sub: s = hi len = 10
sub: s (upon exit) = hi
main: s1 (after call) = hi
sub: len(s) (upon entry) = 10
sub: allocating s
sub: s (upon exit) = hello-from
main: s2 (after call) = hello-from