LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 03-06-2012, 07:51 AM   #1
rafopar
LQ Newbie
 
Registered: Dec 2008
Posts: 5

Rep: Reputation: 0
Problem using C++ library in fortran


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?
Attached Files
File Type: txt GPDs.h.txt (11.2 KB, 3 views)
File Type: txt int_part.cc.txt (3.1 KB, 3 views)
 
Old 03-06-2012, 12:36 PM   #2
rafopar
LQ Newbie
 
Registered: Dec 2008
Posts: 5

Original Poster
Rep: Reputation: 0
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.
 
Old 03-06-2012, 11:50 PM   #3
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
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.
 
Old 03-07-2012, 03:06 AM   #4
rafopar
LQ Newbie
 
Registered: Dec 2008
Posts: 5

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Nylex View Post
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!
 
Old 03-08-2012, 02:41 PM   #5
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
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.
 
  


Reply

Tags
fortran, library, random number


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to use a library in f77 or itel fortran compiler ztdep Programming 1 12-31-2005 03:55 PM
does linux fortran compiler in fedora 4 support VAX FORTRAN? terrence Programming 17 08-31-2005 08:59 AM
Matlab7 R14 library & Intel Fortran AMD64 t2dreamer Linux - Software 0 06-05-2005 04:59 AM
how to compile fortran library and wrap it in C/C++ elvislu Programming 1 05-18-2005 01:19 AM
How can I PATH the intel fortran library? souaw Mandriva 1 04-27-2004 04:34 PM


All times are GMT -5. The time now is 02:47 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration