This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Fix EQUIVALENCE vs. SAVE (PR fortran/18518)


Steve Kargl wrote:
I'm beginning to dislike Chapter 14 of F95 (or Chapter 16 of F2003).

14.7.6    Events that cause variables to become undefined
Variables become undefined as follows:
      (1)   When a variable of a given type becomes defined, all
            associated variables of different type become undefined. ...

subroutine t(y)

   real x
   integer i
   save x,i
   equivalence(x,i)

   interface
      subroutine foo(i, x, y)
         integer, intent(in) :: i
         real, intent(in) :: x
         real, intent(inout) :: y
      end subroutine foo
   end interface
   interface
      subroutine bar(i, x, y)
         integer, intent(in) :: i
         real, intent(in) :: x
         real, intent(inout) :: y
      end subroutine bar
   end interface

   if (y < 0.) then
      i = 0
      !
      ! x is undefined?
      !
      call foo(i,x,y)
   else
      x = 1.
      !
      ! i is undefined?
      !
      call bar(i,x,y)
   end if
end

Is this conforming? That is, can an undefined variable
be used as an INTENT(IN) function argument. If it is
conforming, does it make sense?

I can't find any reason why it wouldn't be standard-conforming, though proving negatives is difficult, and I can't see any place where the standard states it positively.


What it does state (in section 12.5.2.1) is that non-INTENT(IN) dummy arguments can be referenced if the associated actual argument is defined -- which implies the possiblity that it could be undefined. And in looking at all the mentions INTENT(IN), I see nothing specific about requiring definition.

Thus, I would claim that this is conforming.

It also does, I believe, make sense -- so long as foo only internally references i, not x, and bar only internally references x, not i. (In which case, I'm not sure why you'd be passing them as arguments in any real-life situation, but that's irrelevant to the question.)

In particular, I don't see why it is in principle any different from this, with regards to undefined dummy arguments:

program a
  real :: b, c
  c = 2
  d = f(b,c)
contains
  function f(x,y)
    real, intent(in) :: x,y
    f = y**2
  end function
end

- Brooks


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]