Re: declaration order
- From: "Colin Watters" <boss@xxxxxxxxxxxxx>
- Date: Sun, 27 Feb 2011 22:05:22 -0000
<tholen@xxxxxxxxxxxx> wrote in message
"robin" <robin51@xxxxxxxxxxx> writes:
This is old-fashioned code.
Better to define ARRAY as REAL :: ARRAY ( : )
Then you have:
SUBROUTINE SAMPLE (ARRAY)
REAL :: ARRAY( : )
INTEGER :: N
N = UBOUND(ARRAY,1)
I'm unfamiliar with UBOUND. When was it introduced in the standard?
2003 I think.
Problem with this advice however, is that it (the "(:)" dimension for
ARRAY) requires that the subroutine has an "Explicit Interface". This is
best achieved by putting subroutine sample into a module, and USEing the
module in the calling code. There is nothing at all wrong with doing this,
in fact I reccommend it.
....So why did I call it a "problem"?
BECAUSE, if you don't make the interface explicit, the code won't do what
you want. It may fail to compile if you're lucky, or it may crash during
execution if you are less lucky. And if you're completely out of luck, it
will run with no apparrent problem, but produce the wrong answer.
Email: my qname at domain dot com