Can anyone explain this error?

Tobias Burnus burnus@net-b.de
Mon Dec 7 17:42:00 GMT 2009


On 12/07/2009 05:26 PM, Dominique Dhumieres wrote:
> The following code (extracted from gfortran.dg/bind_c_usage_10.f03)
>   integer(c_int) function func1() bind(c, name="myFunc1")
>     real(c_float) :: func1ent
>   entry func1ent()
> gives the following error when compiled with -fdefault-integer-8:
>
> Error: FUNCTION result func1 can't be of type INTEGER(4) in FUNCTION func1 at (1)
>
> Is this error expected? If yes, why? (don't answer that I should not use the 
> -fdefault-*-8 optionsi, I know!-).
>   

Don't use ENTRY :-)

Read the last part of the following quote from the Fortran 2003 standard
in 12.5.2.4:

"If the characteristics of the result of the function named in the ENTRY
statement are the same as the characteristics of the result of the
function named in the FUNCTION statement, their result variables
identify the same variable, although their names need not be the same.
Otherwise, they are storage associated and shall all be nonpointer,
nonallocatable scalars of type default integer, default real, double
precision real, default complex, or default logical."

As integer(c_int) and real(c_float) are different data types, both need
to be default integer/reals. That works (by chance) with default
settings but with -fdefault-real-8 or -fdefault-integer-8 this is no
longer the case and thus it fails. This is not technical unfixable
problem, but just a how it was standardized.

Tobias



More information about the Fortran mailing list