- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I've had a couple of people on my development team do this, now, and I can't believe it's legal but not only don't the compilers (CVF, IVF, Lahey) complain about it -- it seems to work!
Imagine:
Global variable: SomeNumber (integer, in a data only module)
in another module...
subroutine x(parameters)
...
Logical MyArray(SomeNumber)
....
use MyArray in a variety of statements
end subroutine.
Note that SomeNumber will be set prior to this subroutine call but it is a variable, not a parameter where it is declared.
I prefer that they allocate and deallocate in this situation. But is the above even legal?
Comments appreciated.
Linda
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I was very surprised. I never noticed that such a construction works. But when I read the Language Reference Manual about "Specification expressions" I must admit the correctness of the array declaration.
In the following::
Code:
subroutine sub() use mod1 integer arr(n) ... end
n is an specification expression. That is a restricted expression of type integer and filled with a scalar value. n should be made accessible for instance by use association (via the modulemod1 in our example). So if n is preset in the module mod1 or set in another routine prior to the call to sub, then the array allocates n integers.
As I remark, it was new for me. I also don't know when this feature is introduced in Fortran. Is it specific Fortran 90 or 95?
Guus
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There's a couple of different features here. First, automatic arrays, local variables whose bounds are not known untiil the routine is entered, are new in F90. Similarly, use and host association are new in F90. F77 (and F66) had the concept of adjustable arrays as arguments, where you could say:
subroutine sub (a,j)
real a(j)
You knew that. But you could also have this:
subroutine sub (a)
common j
real a(j)
This is also legal in F77. Use and Host association just extend the ways that the value of the bound can be communicated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ewwww. I probably knew it but put it out of my mind! I'm not sure I want to tell others in my team of developers about it -- seems like it could be different on different compilers. I already have enough of those headaches!
Thanks for the reply.
Linda
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I would not expect it to be different on different compilers, unless there's a bug. But this isn't an area I've seen bugs in.
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page