This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
calling C function from program.
- From: Ganesh Ramakrishnan <gangesind at yahoo dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Fri, 15 Feb 2002 05:34:23 -0800 (PST)
- Subject: calling C function from program.
sir/madam,
I am facing some problem, when i call a C
function from a fortran program & compile it using
g77.
Here is my fortran program ---->
------------------------------------------------------
program hello
call callC("calling C program")
print *, "hai"
end
-------------------------------------------------------
Here is my C function ---------->
-------------------------------------------------------
callC_(x)
char* x;
{
printf("%s\n", x);
}
----------------------------------------------------
Now if i compile this with g77, I am getting the
output like this
-----------------------------------------------------
calling C programhai
hai
------------------------------------------------------
The argument which i am passing to the C
function("calling C program") is appended with the
output of the next 'print' statement("hai"). if i
append '\0' at the end of that argument("calling C
program\0"), then it is working fine. Why is it like
this.
I am compiling the program like this.
---------------------------------------------------
g77 "fortran file" "c file"
Will you please suggest me the right way to call
a C function from fortran program?
Expecting your earliest reply.
Thanking you,
R.Ganesh
__________________________________________________
Do You Yahoo!?
Got something to say? Say it better with Yahoo! Video Mail
http://mail.yahoo.com