- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
In a Fortran DLL which is called from C, I use iso_c_binding which defines the numeric kinds c_double, c_int etc.
I have been in the practice of pedantically writing 'entry routines' into the Fortran DLL, where all the incoming arguments are converted into their equivalent native Fortran types, for example:
In a Fortran DLL which is called from C, I use iso_c_binding which defines the numeric kinds c_double, c_int etc.
I have been in the practice of pedantically writing 'entry routines' into the Fortran DLL, where all the incoming arguments are converted into their equivalent native Fortran types, for example:
[cpp]subroutine foo(bar) bind(c, name='foo') !DEC$ ATTRIBUTES DLLEXPORT :: foo real(c_double), intent(inout) :: bar real(kind(1d0)) :: bar_F bar_F=real(bar, kind(1d0)) call Native_Fortran_Foo(bar_F) bar=real(bar_F, c_double) end subroutine foo
Obviously this works well enough, but there is a time and memory overhead which grows significant when the arguments being passed are actually high-resolution images.[/cpp]
[cpp]In reality, I suspect this is wholly unnecessary: c_double is just a constant, equal to 8, so in the example above bar_F has exactly the same binary representation as bar, at least in Windows. My question is, will this always be true, for example in Linux or (whisper it softly) in other Fortran compilers? Is it legitimate to write:
[/cpp]
[cpp] if (c_double.eq.kind(1d0)) then call Native_Fortran_Foo(bar) else bar_F=real(bar, kind(1d0)) call Native_Fortran_Foo(bar_F) bar=real(bar_F, c_double) end if [/cpp]
[cpp]...or will this turn around and bite me if I compile the code on another platform?
[/cpp]
1 Solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Aaargghh. I thought I had sussed the code insertion function, but it got me again. Sorry for the garbled format.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
What you propose should be portable.

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