PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

Free OpenACC Course

KIND parameter with C interoperable

 
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling
View previous topic :: View next topic  
Author Message
Tuan



Joined: 11 Jun 2009
Posts: 233

PostPosted: Fri Oct 01, 2010 1:17 pm    Post subject: KIND parameter with C interoperable Reply with quote

I have a data type defined using KIND parameter
Code:
INTEGER :: dp = selected_real_kind(P=15)
REAL(KIND=dp), dimension(10) :: arr


Now I want to pass this array to a C function that I call via iso_c_binding. I believe the interoparate type for double in C is real(c_double) in Fortran. However, this doesn't have the same kind with the data I defined above. The compiler gives me the "type mismatch" error.

Code:
INTERFACE
   integer(c_int) function c_foo_func (arr, size) bind(c)
       real(c_double) :: arr
       integer(c_int), value :: size
   end
end interface


Could someone suggest me a solution for this.
Thanks
Tuan
Back to top
View user's profile
mkcolg



Joined: 30 Jun 2004
Posts: 6693
Location: The Portland Group Inc.

PostPosted: Fri Oct 01, 2010 2:17 pm    Post subject: Reply with quote

Hi Tuan,

"arr" isn't a real, it's an array of real. So if you're calling c_foo_func using just 'arr', then you should get a rank mismatch.

To fix, try adding a 'dimension(*)' in the interface:

Code:
INTERFACE
   integer(c_int) function c_foo_func (arr, size) bind(c)
       real(c_double), dimension(*) :: arr
       integer(c_int), value :: size
   end
end interface


Hope this helps,
Mat
Back to top
View user's profile
Tuan



Joined: 11 Jun 2009
Posts: 233

PostPosted: Sat Oct 02, 2010 8:16 am    Post subject: Reply with quote

Thanks, Mat

Tuan.
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling All times are GMT - 7 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © phpBB Group