- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
We are calling into Fortran code from C++, using these compiler arguments: /4I4 /real-size:64 /iface:mixed_str_len_arg
The code defines:
typedef unsigned long STRLEN;
void __stdcall MFSINI( CHARACTER *pword, STRLEN PWORDLEN, INTEGER *ierno, INTEGER *ierrls, CHARACTER *errmes, STRLEN emlen );
And it works fine in 32-bit mode. But in 64-bit mode it crashes when assigning a string to errmes. It works though if we have:
typedef __int64 STRLEN;
Keep in mind that we are using Visual C++ which perversely has unsigned long of four bytes in 32 and 64 bit mode.
So my question is, there a way to control the size of the hidden string length argument? Is it always 4 bytes in 32-bit mode and 8 bytes in 64-bit mode? (Please confirm the latter). Can you force it to be 4 bytes in 64-bit mode? Is there a /4I4 equivalent to set it?
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Use size_t in C to declare this argument. You can't control the size. You might also look at the Fortran 2003 C interoperability features that would let you avoid passing this argument, though then you would have no size at all.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Lionel, you are awesome! I should have have thought of size_t!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The definition for STRLEN is not in our code, but rather API files we receive from a vendor, so I shall talk to them about getting it changed. They likely do not see an issue because even though they support 64-bits, only Microsoft Visuall C++ 64 bits has long types that are the same size as they are in 32-bits.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If this is not your Fortran code, then don't bother them about changing. Using size_t will do what you want.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page