Re: optional assumed-shape array



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
.



Relevant Pages

  • Re: In Outlook add a folder then move a message to it.
    ... But Mike, i am still getting an error message of "Unknown COM Status Code" ... >> folder number of a folder? ... >> ENDIF ...
    (microsoft.public.fox.vfp.forms)
  • Re: Broadband speeds
    ... Mike wrote: ... Think of an asymptote where the function approaches ... Some people always refuse to believe that, ... But it is easy to make the argument by contradiction: ...
    (uk.legal)
  • Re: ENDIF expected... but why?
    ... Hi Mike, ... >> If you take a look at the reformatting of your example, ... the endif is missing << ...
    (comp.databases.paradox)
  • Re: Gore wins Nobel Peace Prize
    ... Mike. ... It was a joke. ... I retract my comment about your inability to ... see the contradiction in what you said. ...
    (rec.sport.golf)
  • Re: Broadband speeds
    ... Mike wrote: ... Think of an asymptote where the function approaches ... Some people always refuse to believe that, ... But it is easy to make the argument by contradiction: ...
    (uk.legal)