- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have a function in Fortran:
integer(our_int) function samplesize( maxn, delta, conf, msgLen, iMsg) result( answer )
!DEC$ ATTRIBUTES DLLEXPORT, C :: samplesize
....
our_int is set to be: selected_int_kind(9)
It returns -1 when there is an error, but when I call it in C below, I got 4294967295 (2**32 -1). After I change
integer(our_int) to integer(8), it seems to fix the problem, I wonder why selected_int_kind(9) doesn't
work?
Thanks!
Liz
extern long samplesize(long maxn, double delta, double conf, long msgLen, int *iMsg);
#include <stdio.h>
#include <stdlib.h>
long Calculate(long maxn, double delta, double conf, char* errMsg)
{
long answer;
...
answer = samplesize(maxn, delta, conf, ERR_MSG_LENGTH, iarr);
...
return answer;
}
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You would need selected_int_kind(10) or (preferably, with USE iso_c_binding) c_long, to get a 64-bit integer kind corresponding with long in 64-bit linux C. The c_long selection would adjust automatically if you happened to change between targets where C uses 32-bit or 64-bit long.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear Tim:
Thanks! This is very helpful, I wonder in Mac, selected_real_kind(15,307) in FORTRAN is compatible with double in C?
How about for Windows (32-bit and 64-bit)? So far, we used selected_int_kind(9) for long in C and selected_real_kind(15,307) for
double in C and they worked in 32-bit and 64-bit Windows. We are developing plugins for both Windows and Macs, want to
make sure that we did everything right.
Thanks!
Liz
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
lxh37 wrote:
Dear Tim:
Thanks! This is very helpful, I wonder in Mac, selected_real_kind(15,307) in FORTRAN is compatible with double in C?
How about for Windows (32-bit and 64-bit)? So far, we used selected_int_kind(9) for long in C and selected_real_kind(15,307) for
double in C and they worked in 32-bit and 64-bit Windows. We are developing plugins for both Windows and Macs, want to
make sure that we did everything right.
Thanks!
Liz
[/quote
On all platforms supported by Intel, C double is in fact compatible with Fortran selected_real_kind(15), which would the same as c_double.
The most confusing C compatibility issue is the one with long, where most 64-bit targets (all gcc ones) set long as int64_t, while 32-bit targets (and also Microsoft 64-bit compiler) set long as int32_t. That makes a good case for using c_long.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page