Solved

how to call C function in Fortran?

Posted on 2003-10-21
5
238 Views
Last Modified: 2013-11-08
How a function written in C-language can be called in Digital Fortran?
cancermcs
0
Comment
Question by:cancermcs
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 6

Accepted Solution

by:
Ajar earned 75 total points
ID: 9596627
cancermcs ,

 Are you working on  Digital / VAX-VMS platform ?

The principal steps involved are :

1. Define the funciton in a C file   with the arguments  passed as pointers
    the reason is that fortran uses variables by reference always.
    e.g  a  c function for fortran programs

void  functin_xx(char * text, int * number)
{
    printf("The text is %s  and the number is   %d",text,number);
}



in your fortran program use (i am not very sure of the syntax !!)
---
txt  CHARACTER*16  = 'abced\n\0'
numb  INTEGER

--
--
CALL   FUNCTION_XX(txt,numb)



Compile these programs sepreatly

then link  them together to form an executable .

you can run the executable..


==================
If your os is other than VAX then the c function should have '_'  prefixed to its signature e.g
_function_xx







0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question