[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Use of C++



Ronny Glöckner wrote:

Dear Werner

We have some mathematical tools in C++ (called "diffpack"). We would like to
include this in some TRNSYS components. Do you have any recommendations on
how to to this. All other components that we have made are in fortran. Could
we call a C++ subroutine (in a dll) from a fortran file and then link this
to TRNSYS.

Any suggestions on solutions and thing sto read are most welcome.

Regards

Ronny Glöckner
_______________________________________________________________
Ronny Glöckner - Research Scientist, PhD  tlf(w) +47 63 80 61 68
Institute for Energy Technology (IFE)	(p) 	 +47 22 65 16 33
Instituttveien 18					(mob)  +47 96 61 85 88
P.O. Box 40			 			fax(w) +47 63 81 29 05
N-2027 KJELLER			       	e-mail ronnyg@ife.no
http://www.ife.no







Usually there are some points that zou must consider when mixing C/C++ with Fortran. Try to look how your Fortran-compiler handels function and variable names. Then try to figure out how your Fortran compiler passes function arguments.

The following applies to Fortran 77 compilers. I don't know how Fortran 95 compilers behave and if C++ classes can be accessed from Fortran 95.

Many compilers handle your Fortran function "MyFunc" as "myfunc_" or "MYFUNC_": They add a trailing underscore and make everything uppercase or lowercase.

Function arguments are usually passed by pointer.

You must follow the rules of your compiler in order to make yout functions visible to the Fortran compiler.

Then the most important thing is that your prototypes should be exported with "export C" in order to tell your linker that you want to follow C-linking conventions, which is understood by every compiler on your system.

Last not least, you must not export C++ construts, but C constructs: make your classes accessible by C functions that pass everything by reference and not by value.

Peter