- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi everybody,
I've been using the Fortran-C interoperability features for some time now but always for accessing variables. I cannot figure out how to access a constant from inside a module. I have the following example:
module testing integer, parameter :: const_int=160 integer :: var_int end module testing
I compile with:
ifort -traceback -fPIC -module obj/Release/ -c testing_mod.f90 -o obj/Release/testing_mod.o
If I execute objdump -x testing_mod.o, I get:
SYMBOL TABLE: 0000000000000000 l df *ABS* 0000000000000000 testing_mod.f90 0000000000000000 l d .data 0000000000000000 .data 0000000000000000 l d .bss 0000000000000000 .bss 0000000000000000 l d .text 0000000000000000 .text 0000000000000000 l d .note.GNU-stack 0000000000000000 .note.GNU-stack 0000000000000000 l d .comment 0000000000000000 .comment 0000000000000000 l d .eh_frame 0000000000000000 .eh_frame 0000000000000000 l d .trace 0000000000000000 .trace 0000000000000000 g F .text 0000000000000010 testing._ 0000000000000004 O *COM* 0000000000000008 testing_mp_var_int_
I cannot see the const_int and I cannot access it from C. I can bind the variable (var_int) and select the name but when I try to bind the constant by adding bind(C, name="const_int"), I get:
testing_mod.f90(3): error #6406: Conflicting attributes or multiple declaration of name. [CONST_INT] integer, parameter, bind(C, name="const_int") :: const_int=160 -----------------------------------------------------^ compilation aborted for testing_mod.f90 (code 1)
Any idea on how to access it? I work under Debian Linux 7 and my compiler is: Version 14.0.2.144 Build 20140120
Thanks in advance,
Petros
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I found my answer... Really sorry for the spamming. I was searching with wrong keywords. --> http://software.intel.com/en-us/forums/topic/291657
Found a workaround:
module testing use iso_c_binding integer, parameter :: const_int=160 integer, protected, bind(C, name="const_int") :: const_int_c data const_int_c/const_int/ integer :: var_int end module testing
Seems to work fine. Thanks again!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
p3tris wrote:
I found my answer... Really sorry for the spamming. I was searching with wrong keywords. --> http://software.intel.com/en-us/forums/topic/291657
Found a workaround:
module testing use iso_c_binding integer, parameter :: const_int=160 integer, protected, bind(C, name="const_int") :: const_int_c data const_int_c/const_int/ integer :: var_int end module testingSeems to work fine. Thanks again!
Why can't you simply add an accessor method in your module instead?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
FortranFan wrote:
Quote:
p3tris wrote:I found my answer... Really sorry for the spamming. I was searching with wrong keywords. --> http://software.intel.com/en-us/forums/topic/291657
Found a workaround:
module testing use iso_c_binding integer, parameter :: const_int=160 integer, protected, bind(C, name="const_int") :: const_int_c data const_int_c/const_int/ integer :: var_int end module testingSeems to work fine. Thanks again!
Why can't you simply add an accessor method in your module instead?
Yes, that was my other option. But as I have more than one contstants to access, I prefered this one. I guess both work fine.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
p3tris wrote:
Quote:
FortranFan wrote:Why can't you simply add an accessor method in your module instead?
Yes, that was my other option. But as I have more than one contstants to access, I prefered this one. I guess both work fine.
Re: "both work fine" - some comments:
- As one's program gets bigger and bigger and more coders work on it, I usually find such direct access to data is fraught with danger, especially in mixed-language environments.
- The accessor method provides good data encapsulation methodology which is one of the benefits of using modules.
- I'm not a fan of DATA statement and have "deprecated" its use in my code. It can interfere with thread safety and hinder parallelization efforts
My 2 cents,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
FortranFan wrote:
Quote:
p3tris wrote:Quote:
FortranFan wrote:
Why can't you simply add an accessor method in your module instead?
Yes, that was my other option. But as I have more than one contstants to access, I prefered this one. I guess both work fine.
Re: "both work fine" - some comments:
- As one's program gets bigger and bigger and more coders work on it, I usually find such direct access to data is fraught with danger, especially in mixed-language environments.
- The accessor method provides good data encapsulation methodology which is one of the benefits of using modules.
- I'm not a fan of DATA statement and have "deprecated" its use in my code. It can interfere with thread safety and hinder parallelization efforts
My 2 cents,
Thanks! I think I'll create some accessors as you suggest. However, the DATA statement, I use it in other situations not relating to the C interface. Could you give me some source of information about its interference with parallelization? Or is it a personal observation?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
![](/skins/images/BC9A7A3465121B56B278007F4EE8899F/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