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

C++ and Fortran source in one Project

weingart__daniel
Beginner
1,558 Views

Hi,

in front i´m complete new with Fortran.

So my Problem is: We have an realy old Software Project. It was generatet with Compaq Visual Fortran 6.1  and includes Source Files in *.cpp and *.for.

From my point of view, it was extremly confortable to compile  and Debug this Project in one step by pressing F5.

My question is: Is there a way to do the same with VisualStudio and IntelParallelstudio XE 2016?

In best case i would like to convert my Compaq c++ DSW to VisualStudio.

Until now i only found examples where a Fortran dll was use by a c++ Programm. IBut i would like to create a dll  from c++ and Fortran sourcefiles.

 

Best 

Daniel

 

0 Kudos
24 Replies
Steven_L_Intel1
Employee
218 Views

Thanks for this. In your snippets I overlooked something you missed. You need BIND(C) on the functions in the abstract interface. This explains both why SUBTRACT didn't work and why adding VALUE didn't work.

First, if you don't say BIND(C), then functions that return structures pass a hidden first argument for that. BIND(C) uses the C convention so that "small" structures can be returned in registers.

Second, VALUE means pass-by-value only for BIND(C) interfaces. Otherwise, it means pass a writable copy by reference.

0 Kudos
NotThatItMatters
Beginner
218 Views

Steve, thank you for pointing out the missing BIND(C) attribute.  Add and Subtract now work as advertised.  I am still having some trouble with my Multiply function taking char * input.  I assume this will mean TYPE (C_PTR) input but the attachment of this input to Fortran CHARACTER variables is eluding me.  I have not given up yet.

0 Kudos
Steven_L_Intel1
Employee
218 Views

For char*, declare the argument as CHARACTER, DIMENSION(*) and pass a character variable. It will pass the address of the variable. Don't forget about a NUL termination.

0 Kudos
NotThatItMatters
Beginner
218 Views

Okay, my one mistake (again) was to not specify the VALUE attribute with the input arguments of TYPE (C_PTR).  That did the trick.  I have attached my test code for those who might need to use it.

0 Kudos
Reply