gfortran question about optional subroutine arguments

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From what I read, what I need to do is doable in f90/f95 using optional arguments? But I am porting some very old fortran77 stuff and am using the -std=legacy switch. I'm basically trying to figure out how to call a subroutine with fewer arguments than the subroutine was declared with. The call works but in the code below I get a segfault when the subroutine attempts to access the unpassed argument. The old fortan77 had no problems with this, I assume because even when not passed in, the subroutine declaration gave the argument a valid address??

      program test
      implicit none

      integer*4 arg1 /10/
      integer*4 arg2 /20/

      call sub1(arg1)
c    the old fortran77 call would have been
c    call sub1(arg1,)
      stop
      end

      subroutine sub1(arg1, arg2)
      implicit none

      integer*4 arg1
      integer*4 arg2

      arg2 = 0     ! causes segfault in gfortran
c
c    A segfault also occurs in some_other_sub if arg2 is accessed.
c
      call some_other_sub(arg1,arg2)  !

      return
      end

Yet a loc(arg2) any where is the line _seems_ to provide a valid address???

Is there a way this be done using -std=legacy switch


Thanks and Regards
Mark


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux