Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ASSOCIATE Construct for Procedure Arguments

10 views
Skip to first unread message

Andrew Baldwin

unread,
May 19, 2011, 4:18:23 PM5/19/11
to
I keep seeming to get in trouble with the ASSOCIATE construct. This
time I've come across unexpected behavior with the following code:

subroutine print_int (i)
integer, intent (in) :: i(2)

print *, i
end subroutine print_int

program main
interface
subroutine print_int (i)
integer, intent (in) :: i(2)
end subroutine print_int
end interface

integer, allocatable :: foo(:,:)

allocate (foo(2,2))
foo(:,1) = [1, 2]
foo(:,2) = [3, 4]

call print_int (foo(:,2))

associate (bar => foo(:,2))

print *, bar

call print_int (bar)

end associate
end program

My expectation was that the three print statements that are executed by
this program would produce the same output. However, when I compile
with gfortran 4.7.0 20110514 and run it locally, the output I have looks
something like

3 4
3 4
33275912 0

where the first number of the last print statement varies for each call.

Looking at the standard it seems to me that this should be conforming,
but I'm still quite new to some of the terminology being used. Is this
code standard conforming?

Wolfgang Kilian

unread,
May 20, 2011, 2:17:50 AM5/20/11
to

For the records: works as intended with nagfor 5.2, no errors or
warnings (if -f2003 option set)

-- Wolfgang

--
E-mail: firstnameini...@domain.de
Domain: yahoo

JWM

unread,
May 20, 2011, 3:28:32 AM5/20/11
to
On Fri, 20 May 2011 00:17:50 -0600, Wolfgang Kilian
<see...@domain.invalid> wrote:

>
> For the records: works as intended with nagfor 5.2, no errors or
> warnings (if -f2003 option set)
>
> -- Wolfgang
>

It also works as intended with ifort 12.0.4, no errors, warnings or
additional options required.

--
John
Using Opera's revolutionary email client: http://www.opera.com/mail/

0 new messages