Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Beginner
3 Views

Incorrect Fortran code?

Hello, 

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?

BR, Jan.

0 Kudos
1 Reply
Highlighted
New Contributor II
3 Views

That's why interface and

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.

0 Kudos