- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I write a new function as follow
integer function openf(c) result(i)
!DEC$ ATTRIBUTES DLLEXPORT :: openf
character(len=*)::c
open(11,file=c)
!open(newunit=i,file=c)
i=11
end function
then I compile it into runtime library, then I call "openf" by
i = openf("ccc.txt")
inquire(i,exist=j)
write(*,*)j
inquire(file="ccc.txt",exist=j)
write(*,*)j
it will work normally and return both True
while when I use the parameter "newunit", as
integer function openf(c) result(i)
!DEC$ ATTRIBUTES DLLEXPORT :: openf
character(len=*)::c
open(newunit=i,file=c)
end function
Then, it failed to open the file and the first inquire return false.
Is this a reasonable?
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
When using the "result(i)" on function declaration, you do not also attribute the function with return type "integer" ("integer function ...").
I am surprised a compiler error message did not report. Try:
function openf(c) result(i)
!DEC$ ATTRIBUTES DLLEXPORT :: openf
character(len=*)::c
open(newunit=i,file=c)
end function
Additionally, use implicit none and declare all the dummy arguments
function openf(c) result(i)
!DEC$ ATTRIBUTES DLLEXPORT :: openf
implicit none
integer :: i character(len=*)::c
open(newunit=i,file=c)
end function
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I filled to replay the question until I find a VPN.
When I compile them with the same options( both debug or release, multithread dll), it work fine.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It is not clear if, in the scope containing the statement "i = openf("ccc.txt")", the identifier OPENF if of type INTEGER. WIth default typing, OPENF is of type default real, so the assignment statement would probably set i = 0 as a result of erroneous type conversion.
Please check and correct if needed.
![](/skins/images/D2683F18326913BBA0436CB7114DD569/responsive_peak/images/icon_anonymous_message.png)
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page