Re: Subroutine "arguments"??
- From: nospam@xxxxxxxxxxxxx (Richard Maine)
- Date: Tue, 31 Jul 2007 09:41:12 -0700
<li.simula@xxxxxxxxx> wrote:
subroutine sub(A)
real(8), intent(in) :: A(10,10)
...
end subroutine
call sub(B) ! where B is a matrix B(10,10)
A is a matrix. I known that the passing actual arguments to dummy
arguments is by passing the address of actual arguments.
Well, then what you know is wrong. That is a common mechanism, but the
standard does not specify that it must be used. It is often used, but
not always. There are situations where it basically cannot be used. For
example, assumed shape dummy arguments are almost never passed by
address.
Why are you asking anyway? For the most part, you don't need to know
that level of implementation detail. The compiler will take care of that
for you. That's what compilers do. In the rare situations where youy
might need to know it, you'd need a lot deeper understanding than I see
in the questions below. I'd suggest you mostly not worry about
implementation details at that level. If you do happen to do anything
that depends on such implementation details, you'll probably get in
"trouble" when it doesn't work that way in all cases.
I will go ahead and give the most common answers, but you really should
not depend on this.
But I want to
ask that it is passing only the address of A(1,1) or all the address
of A(1,1),A(1,2).....A(10,10)?
No implementation will ever pass the addresses of all the elements. That
is completely impractical. If it passes by address at all, it will pass
the address of the first element.
And if A or B is a derived type argument, is it also pass by the
address? (There is a problem is that derived type argument has
discontinus memory, I'm not sure)
No. There is nothing unusual about derived type arguments in this
regard. They do noty tend to have discontiguous memory, except that
1. There can be padding for alignment purposes. But that will be
consistent within a given compiler. It would not affect argument
passing.
2. There can be things like internal pointers or allocatables, with
memory elsewhere. But in that case, the pointer or allocatable has the
needed information.
In either case, all the issues are within a single element. There is
nothing unusual about arrays of derived type.
--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain
.
- Follow-Ups:
- Re: Subroutine "arguments"??
- From: tholen
- Re: Subroutine "arguments"??
- References:
- Subroutine "arguments"??
- From: li . simula
- Subroutine "arguments"??
- Prev by Date: Re: Lahey Fortran and Core 2 duo
- Next by Date: Re: Lahey Fortran and Core 2 duo
- Previous by thread: Subroutine "arguments"??
- Next by thread: Re: Subroutine "arguments"??
- Index(es):
Relevant Pages
|