
Q:Fortran call C parameter passing
Dear Chai:
Quote:
> Hi all,
> I have a Fortran code calling a C function. In Fortran, the 6th
> parameter in the calling sequence is declared as,
> INTEGER ISIZE20
> PARAMETER (ISIZE20 = 20)
> In C it was declared as int *sizePtr.
> The problem was that when *sizePtr is assigned to, a SEGV was generated.
> I compared &ISIZE20 in Fortran and sizePtr in C. sizePtr is not pointing
> to the address of ISIZE20.
> It seems that this is caused by ISIZE20 is a constant PARAMETER.
> But how does C function get to know this?
> Thanks,
> Chai Liang
In Fortran, the PARAMETER attribute or statement is used to define a NAMED
CONSTANT. If you pass the named constant as an actual argument, then any
assignment to the dummy argument modifies the value of a named constant.
Obviously, you can't modify the value of a constant.
As Richard Maine pointed out, named constants do not have addresses in
some Fortran implementations. In some other implementations, named constants
DO have addresses but they are located in write-protected (AKA read-only)
areas of memory. If you attempt to modify them, you will get weird and FATAL
run-time errors. I once did what you did in DEC Fortran under VMS back in
1985. I got a {*filter*} program crash along with an error message something like,
"Attempt to modify read-only program section". It took me a while to figure
out exactly what mistake I had made.
--
----------
Sincerely,
Elmbrook Computer Services Voice Phone: (414) 783-5869
17130 W. Burleigh Place Fax Phone: (414) 783-5928
Brookfield, WI 53005 Disclaimer: These opinions are mine alone.
USA They do NOT represent any organization.
"They that can give up essential liberty to obtain a little temporary
safety deserve neither liberty nor safety." -- Benjamin Franklin (1759)