LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Problem using C++ library in fortran (https://www.linuxquestions.org/questions/programming-9/problem-using-c-library-in-fortran-933012/)

rafopar 03-06-2012 07:51 AM

Problem using C++ library in fortran
 
2 Attachment(s)
Hi guys,

I have three functions
(cm_angles, bh_cros_section, and int_part) which are in C++, and I need to call them in a FORTRAN program.

I have created shared libraries of these functions
and linked with FORTRAN program, and
in FORTRAN program I made a call e.g. "call cm_angles(arg1, arg2, ...)".

From the first sight these functions work correct,
and calculated values are correct also, but the
function int_part (only int_part), causes a problem.

The problem is:
after the first call of int_part, the call of random number
generator function (ranmar) in FORTRAN gives "NAN".
Without calling int_part ranmar works well.

If anyone want to look, the int_part and it's header file are attached.
The FORTRAN code consist of many files, and is
complicated, therefor I didn't attach it.

Any clue or idea about this?

rafopar 03-06-2012 12:36 PM

I found a mistake.

the type of int_part function was double.
I am not sure exactly why, but in order to
implement the function in FORTRAN, the type should be void.
I have changed it to void, and it worked.

Nylex 03-06-2012 11:50 PM

The function doesn't return a value, so regardless of having to use it in a Fortran program, it should be declared with a return type of void.

rafopar 03-07-2012 03:06 AM

Quote:

Originally Posted by Nylex (Post 4620481)
The function doesn't return a value, so regardless of having to use it in a Fortran program, it should be declared with a return type of void.

Thanks for reading codes.
Yes I agree with you.
I wonder why it worked in C++ without giving an error.

Thanks one more time!

Nylex 03-08-2012 02:41 PM

No problem. With g++, if you compile with -Wall (to enable all warnings), you'll get a warning for your situation. I think there's an option to make warnings become errors (so that compilation fails), but I don't remember what it is.


All times are GMT -5. The time now is 03:22 AM.