Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29342 Discussions

Size of hidden string length argument in 64-bits

van_der_merwe__ben
New Contributor II
1,122 Views

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?

0 Kudos
4 Replies
Steven_L_Intel1
Employee
1,122 Views

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.

0 Kudos
van_der_merwe__ben
New Contributor II
1,122 Views

Lionel, you are awesome! I should have have thought of size_t!

0 Kudos
van_der_merwe__ben
New Contributor II
1,122 Views

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.

0 Kudos
Steven_L_Intel1
Employee
1,122 Views

If this is not your Fortran code, then don't bother them about changing. Using size_t will do what you want.

0 Kudos
Reply