Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Incorrect Fortran code?

Marc__Jan
Beginner
363 Views

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
GVautier
New Contributor II
363 Views

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
Reply