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

Passing character args from C++ to Fortran with 64-bit build

John6
Novice
911 Views
In the attached (64-bit build) solution, I am passing C++ character strings into FORTRAN by passing a char* and int.
Inside the FORTRAN (at line 12), I set a substring of one of the arguments to some value.
What I would like to know is this:
Why do I get the following error message when the /check:bounds option is on?
The error message is: forrtl: severe (408): fort: (19): Dummy character variable 'HERR' has length 255 which is greater then actual variable length -3689348818177883905
This error did not happen with a 32-bit build. Why the long negative integer? Is it a compiler bug?
I am using IVF 11.1.051 (w_cprof_p_11.1.051)
0 Kudos
1 Solution
Steven_L_Intel1
Employee
911 Views
size_t usually works, but I think intptr_t is more "correct".

View solution in original post

0 Kudos
7 Replies
Steven_L_Intel1
Employee
911 Views

You declared the character lengths as "int" in C. They need to be an "address-sized int".
0 Kudos
TimP
Honored Contributor III
911 Views

You declared the character lengths as "int" in C. They need to be an "address-sized int".
Shouldn't size_t work? I've had a customer who refused to work with a compiler where size_t and int weren't the same, but that rules out 64-bit Windows for sure.
0 Kudos
Steven_L_Intel1
Employee
912 Views
size_t usually works, but I think intptr_t is more "correct".
0 Kudos
John6
Novice
911 Views
Thanks Steve. The intptr_t works perfectly with all builds. I will use this as my standard for passing C++ strings to FORTRAN.

0 Kudos
shanemoneill
Beginner
911 Views

Dear All,

I am getting the very same error as described above however I have not been able to implement the suggested solution.

The following line is where I'm getting the error. This works successfully in x32.

DPBSV("U", &n,&kd,&nrhs,Aptr,&ldA,Xptr,&ldB,&info);

I would be grateful if someone could post an example of the code utilising intptr_t.

Kind Regards,

Shane

0 Kudos
TimP
Honored Contributor III
911 Views

If you have a recent copy of Intel C, the header file is provided:


void DPBSV( char* uplo, MKL_INT* n, MKL_INT* kd, MKL_INT* nrhs, double* ab, MKL
_INT* ldab, double* b, MKL_INT* ldb, MKL_INT* info );

(#define MKL_INT int for the case where you use default integers in Fortran)

It's OK when using the standard Fortran source for this function to omit the string length argument. If you wish to access the length of uplo, which the standard code doesn't do, the string length is appended to the argument list.

void DPBSV( char* uplo, MKL_INT* n, MKL_INT* kd, MKL_INT* nrhs, double* ab, MKL
_INT* ldab, double* b, MKL_INT* ldb, MKL_INT* info, MKL_INT *uplo_len );

MKL_INT uplo_len = 1;

DPBSV("U", &n,&kd,&nrhs,Aptr,&ldA,Xptr,&ldB,&info,&uplo_len);

As the standard Fortran source doesn't handle the interface, and by default you have disagreement between the names used in Fortran and C (unless using Windows), you might consider adding the iso_c_binding declaration on the Fortran side, but that suppresses the hidden length argument.

0 Kudos
shanemoneill
Beginner
911 Views

Thanks Tim your suggestion helped alot!

Kind Regards,

Shane.

0 Kudos
Reply