[Bug libfortran/95293] Fortran not passing array by reference

david.sagan at gmail dot com gcc-bugzilla@gcc.gnu.org
Sun May 24 14:45:32 GMT 2020


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95293

--- Comment #6 from David Sagan <david.sagan at gmail dot com> ---
> program foo
>    real x
>    x = 42
>    call bar(x)
>    print *, x
>    contains
>      subroutine bar(a)
>         real, intent(inout) :: a
>         a = 12
>         x = 0
>      end subroutine bar
> end program foo
> 
> Should this print 12 or 0?  When bar returns 'a' has a value of
> 12, should this value be transferred to 'x' before the print 
> statement is executed?

'a' is passed by reference. Therefore, when the statement 'x = 0' is executed,
the value of 'a' immediately changes to 0. So '0' will be printed.


More information about the Gcc-bugs mailing list