- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi all,
I am having some problems with using global variables with external routines using DLLs. I compile something like this into a DLL:
MODULE my_mod
IMPLICIT NONE
INTEGER, SAVE :: key
EXTERNAL test
CONTAINS
SUBROUTINE call_test(key)
call test(1)
END SUBROUTINE call_test
END MODULE my_mod
SUBROUTINE test(i)
USE my_mod
IMPLICIT NONE
INTEGER :: i
PRINT*,"i=",i
PRINT*,"key=",key
END SUBROUTINE test
I then call the subroutine call_test() from, say, R with the key value as 2 I get the following output:
i=1
key=0
Apologies if I am missing something very obvious I am a Fortran 77 programmer attempting to learn F90/95.
Thanks in advance!
1 Solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In your subroutine call_test you are declaring key as an argument. Therefore, key will be a local variable to the subroutine and not the module variable.
Modify your code like that and it should work:
SUBROUTINE call_test(keyval)
key = keyval
call test(1)
END SUBROUTINE call_test
regards,
Thomas
Thomas
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In your subroutine call_test you are declaring key as an argument. Therefore, key will be a local variable to the subroutine and not the module variable.
Modify your code like that and it should work:
SUBROUTINE call_test(keyval)
key = keyval
call test(1)
END SUBROUTINE call_test
regards,
Thomas
Thomas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Thomas, that's solved my problem! I can't believe I didn't think of doing that!
Quoting - thomas_boehme
In your subroutine call_test you are declaring key as an argument. Therefore, key will be a local variable to the subroutine and not the module variable.
Modify your code like that and it should work:
SUBROUTINE call_test(keyval)
key = keyval
call test(1)
END SUBROUTINE call_test
regards,
Thomas
Thomas
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