Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29280 Discussions

STRUCTURE or COMMON in parameter

sphost
Beginner
1,255 Views

Another problem I meet, trying to call a Fortran function from a C++ program :

How can I pass a structure from C++ in the parameter of the Fortran Function ?

Example :

typedef struct _testst (int test1; int test2) testst, *lptestst;

extern "C" void f1(lptest rec);

What does my Fortran function f1 look like ? In fortran side, do I have to declare rec as a COMMON and how ? Is it also possible to declare it as a STRUCTURE (VMS keyword) ?

If you have any example, it would be great !

Thanks in advance for your answer !

0 Kudos
13 Replies
Steven_L_Intel1
Employee
1,255 Views
You can use the DEC STRUCTURE/RECORD extension, but I don't recommend it. You should use an "interoperable derived type" (and routine). For example:

subroutine f1 (rec) bind(C,name="f1")
use,intrinsic :: iso_c_binding
type, bind(C) :: testst
integer(C_INT) :: test1
integer(C_INT) :: test2
end type testst
type(testst), intent(inout) :: rec
! code goes here
! components are rec%test1 and rec%test2
end subroutine f1
0 Kudos
sphost
Beginner
1,255 Views

Ok, thanks for the information, I will try this.

Nevertheless, if I want to use the DEC STRUCTURE/RECORD extension, what would be the syntax to use it in C++ ?

0 Kudos
Steven_L_Intel1
Employee
1,255 Views
In C++? That's a Fortran extension. You would use it in place of the TYPE declarations in Fortran code.
0 Kudos
sphost
Beginner
1,255 Views
No, I want to know the syntax to declare a STRUCTURE in the Fortran Code as an intent(inout)
0 Kudos
Steven_L_Intel1
Employee
1,255 Views
structure /testst/
integer test1
integer test2
end structure
record /testst/ rec
intent(inout) :: rec

I don't know why you would want to do that rather than the standard-conforming method.
0 Kudos
sphost
Beginner
1,255 Views

Well, this is very simple :

My C++ Project has to call Mathematical Fortran Model made by our technical department. This department used to do their model in VAX VMS.

Now they have to migrate it to a Linux server sothey would like to do the less modification as possible.
That's why I want to keep the syntax of VMS Fortran.

Thanks a lot for your answer !

0 Kudos
Steven_L_Intel1
Employee
1,255 Views
If you really mean VAX, then remove the INTENT line. DEC/Compaq/HP Fortran for OpenVMS Alpha will support INTENT. It also supports TYPE, though not BIND or ISO_C_BINDING.
0 Kudos
sphost
Beginner
1,255 Views
Well, I don't want to keep my model in OpenVMS environnement, I have to migrate it to a Linux Server. So I have to add the intent and BIND and ISO_C_BINDING if I want my model to be called from C++. No ?
0 Kudos
Steven_L_Intel1
Employee
1,255 Views
"Have to"? No. People have been mixing C/C++ and Fortran for many years without these things, but always using extensions and assumed behavior. Now there is a standard-conforming way to do it.

The INTENT is optional and is primarily there to aid in error checking.
0 Kudos
sphost
Beginner
1,255 Views

I understand, but the code of this model containt some call to SYS$ of OpenVMS system that cannot be use in linux.

So the code has to be change in this way. Nevertheless, you mean that the actual syntax used for OpenVMS will be applied to the linux system ? Won't I have any problem if I keep for examplea REAL*4 which has to be modified by C++ ?

0 Kudos
Steven_L_Intel1
Employee
1,255 Views
I don't see a problem with what you propose.
0 Kudos
sphost
Beginner
1,255 Views
I mean, the size of a REAL in Fortran is not the same than in C++, that's why we have to put REAL(C_DOUBLE), so I have to modify my Fortran Code in this way to be able to access this fortran variable throw C++, that's right ?
0 Kudos
Steven_L_Intel1
Employee
1,255 Views
Well, USUALLY the size of default REAL in Fortran is the same as that of float in C, and the size of DOUBLE PRECISION is the same as C's double. Nothing requires that, of course. You can use REAL*4 and REAL*8 (extensions) to be explicit about the size, but you're still making an assumption about what C does. The use of the kind constants in ISO_C_BINDING is intended to eliminate the need for assumptions, but that doesn't mean the code won't work if you "guess right".
0 Kudos
Reply