- Отметить как новое
- Закладка
- Подписаться
- Отключить
- Подписка на RSS-канал
- Выделить
- Печать
- Сообщить о недопустимом содержимом
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?
Ссылка скопирована
- Отметить как новое
- Закладка
- Подписаться
- Отключить
- Подписка на RSS-канал
- Выделить
- Печать
- Сообщить о недопустимом содержимом
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
- Отметить как новое
- Закладка
- Подписаться
- Отключить
- Подписка на RSS-канал
- Выделить
- Печать
- Сообщить о недопустимом содержимом
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.
- Отметить как новое
- Закладка
- Подписаться
- Отключить
- Подписка на RSS-канал
- Выделить
- Печать
- Сообщить о недопустимом содержимом
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.

- Подписка на RSS-канал
- Отметить тему как новую
- Отметить тему как прочитанную
- Выполнить отслеживание данной Тема для текущего пользователя
- Закладка
- Подписаться
- Страница в формате печати