Following program crashes on Linux/x86_64/intel fortran (also gfortran & NAG fortran)
program chk_trim CHARACTER*(30) TAB TAB='RSRDATA_AAAAAA\0' call shady(tab) !! 1st call does not seg fault !! as TAB string is on the stack call shady('RSRDATA_BBBBBB\0') !! this seg faults !! since string passed in argument !! is in non-writable memory region write(*,*) 'tab=',tab end program SUBROUTINE SHADY(TAB) CHARACTER*(16) TAB TAB = TRIM(TAB) !! -- CRASHES HERE -- write(*,*) '--## TAB=', TAB RETURN END
But surprisingly it does not crash on AIX xlf95 (PowerPC). Nevertheless, it looks like invalid Fortran code - is this right?
That's why interface and intent has been added to fortran. Before that, it was a common problem leading to crash or constant value change depending of compiler constant implementation.