- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello
I dont understand whats wrong.
program Test implicit none integer B(6) call Arr(B) read * contains subroutine Arr(A) integer, allocatable :: A(:) print *, UBound(A) end subroutine Arr end program Test
(8): Error: If dummy arg is allocatable, actual arg must be a whole array and not a section.
If Arr will be in DLL but I will lie the interface of Arr like:
interface subroutine Arr(A) !DEC$ ATTRIBUTES DLLIMPORT, ALIAS : 'Arr' :: Arr integer A(:) end subroutine Arr end interface
I.e. A will not be declared in interface as allocatable all works!
And the second and main question: how Arr knows UBound of A!? Especially when Arr is a DLLs subroutine. And it doesnt matter if A is allocatable or integer A(:) (taking-form-array).
I hope someone will explain.
Stanislav
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
When you call a routine where there is an explicit interface saying that the bounds are "assumed-shape" (:), then the compiler knows to pass a "descriptor" rather than just an address. This descriptor has the base address plus all of the bounds information. The called routine expects this and uses info from the descriptor.
It is an error to call a routine with assumed-shape arguments from code that does not have an explicit interface visible for the routine. There are other routine attributes that require an explicit interface - these are listed in the Language Reference.
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
Thx for answer, I understood. What about list I found it (if someone interested):
A procedure must have an explicit interface in the following cases:
If the procedure has any of the following:
A dummy argument that has the ALLOCATABLE, OPTIONAL, POINTER, TARGET, or VOLATILE attribute
A dummy argument that is an assumed-shape array
A result that is an array, or a pointer, or is allocatable (functions only)
A result whose length is neither assumed nor a constant (character functions only)
If a reference to the procedure appears as follows:
With an argument keyword
As a reference by its generic name
As a defined assignment (subroutines only)
In an expression as a defined operator (functions only)
In a context that requires it to be pure
If the procedure is elemental
Actually, I asked this question thats why. Descriptor. Ok. But is he Intel or Fortran specific. I mean, could I give to DLLs subroutine:
interface subroutine Arr(A) !DEC$ ATTRIBUTES DLLEXPORT, ALIAS : 'Arr' :: Arr integer A(:) end subroutine Arr end interface
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I recently posted a simple example how an array descriptor (applicable to array pointers, allocatable arrays and assumed-shape arguments) works and what it contains -- see this thread. Since this Forum still screws the attachments, I'll repost the code as-is there.
Note that the structure differs even for CVF and IVF, so you can't port it to other Fortran compilers. In C, you can declare the called Fortran function to have a struct VF_1D_DESCRIPTOR as the argument matching an assumed-shape/allocatable/pointer array. (Note that half of the code is actually C written in Fortran :-)).
Jugoslav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page