Re: optional assumed-shape array
- From: nospam@xxxxxxxxxxxxx (Richard Maine)
- Date: Fri, 30 May 2008 20:57:22 -0700
Mike <SulfateIon@xxxxxxxxx> wrote:
....
real, optional :: ai(:)....
if(present(ai))then
aaa=0.0
do i=1,size(ai)
aaa=aaa+ai(i)
end do
endif
ai(1)=3 <==="access violation"
I need ai to be optional argument. So how do I "access" ai?
You can't. That's a contradiction in terms. If ai is not present, then
it doesn't exist. There isn't anything for you to access. Perhaps it
might help if you explained what you are trying to achieve. Odds are
that there is a way to do whatever it is that you actually need, but you
can't "access" a non-present optional argument.
It might be that you need a temporary local variable or some such thing.
But without an explanation of what you are trying to achieve I can't
offer much more specific advice other than that you can't do what you
are asking for,
As an aside, note that in addition to the invalid attempt to use ai when
it is not present, you also have a function whose value is not defined,
at least in the acse where ai is not present. That is not allowed. I
assume that this must be an excerpt from something bigger, where the
function value got defined and where the attempt to set a value of ai(1)
had some actual use.
--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain
.
- References:
- optional assumed-shape array
- From: Mike
- optional assumed-shape array
- Prev by Date: Re: warning on running image !!!!!
- Next by Date: NYT disses Fortran
- Previous by thread: optional assumed-shape array
- Next by thread: optional or interface
- Index(es):
Relevant Pages
|
|