error calling c functions from gfortran

Tobias Schlüter tobias.schlueter@physik.uni-muenchen.de
Sat Feb 10 16:58:00 GMT 2007


mike.howell@mchsi.com wrote:
> I get the wrong answer calling c programs from a gfortran program. The same c 
> functions work when called from a c main program. I guess I need some kind of 
> interface statement to call c functions from gfortran. Can anyone help me? I 
> have attached the make file and source code. The shift result is incorrect. A rt 
> shift on the number 8 should return 4 & lft shift 16.
...

> int lshift_(int Num2Shift, int NumBits )
> 
> {
> 	return(Num2Shift << NumBits);
> }
> 

Gfortran passes function arguments by reference, so your function should 
look like
int lshift_ (int *i, int *j)
{
    return *i << *j;
}

That said, Fortran has an intrinsic, ISHFT, which already does what 
you're trying to do, i.e. ISHFT(I, 2) <=> i << 2 etc.

- Tobi



More information about the Fortran mailing list