(j3.2006) BIND(C) on entry statement

Bill Long longb
Wed Jul 6 19:28:39 EDT 2011



On 7/6/11 12:47 PM, Jim Xia wrote:
>
> Is the following program legal?
>
> function fexfun_char(n1) result(n2)
> use iso_c_binding
> character(kind=C_CHAR), value :: n1
> character(kind=C_CHAR) n2
> n2 = 'g'
> return
> entry exfun_char(n1) result(n2) bind(c)
> n2 = n1
> end function fexfun_char
>
> There aren't any rules forbidding this in the standard. But the storage
> association between function return result and entry result in this case
> seems to suggest fexfun_char should have a binding label as well.
>

I'm not clear on why there is a problem here.  The result for 
fexfun_char is n2. The result for exfun_char is the same n2 - there is 
only one declaration for n2 in the program. So the results are not only 
storage associated, they are actually the same variable.

I expanded the code to be executable:

module modu

contains
function fexfun_char(n1) result(n2)
use iso_c_binding
character(kind=C_CHAR), value :: n1
character(kind=C_CHAR) n2
n2 = 'g'
return
entry exfun_char(n1) result(n2) bind(c)
n2 = n1
end function fexfun_char
end module modu


program test
use modu
character :: a1, a2

a1 = fexfun_char("1")
a2 = exfun_char("2")

print *, a1, a2

end program test

which seems to work fine with both the Cray and Intel compilers.

Cheers,
Bill

-- 
Bill Long                                           longb at cray.com
Fortran Technical Support    &                 voice: 651-605-9024
Bioinformatics Software Development            fax:   651-605-9142
Cray Inc./Cray Plaza, Suite 210/380 Jackson St./St. Paul, MN 55101





More information about the J3 mailing list