Problem with procedure pointers

Janus Weil janus@gcc.gnu.org
Thu Mar 10 12:40:00 GMT 2011


Hi Arjen,


> And where I would expect the computed area to be 6, I get zero. Hence
> the write statements.
> Here is the output of the program:
>
>   1.0000000       2.0000000      5.88534145E-39  5.88534145E-39
>  This:   6.14154925E-39  6.14152123E-39
>  Special area:   0.0000000
>  This:   6.14154925E-39  6.14152123E-39
>  Second special area:   0.0000000
>
> (My guess is that the two strange numbers at the end of the first line
> are procedure pointers)
>
> As you can see in the output, the argument that gets passed bares very
> little resemblance
> to the rectangle object I have defined.
>
> Can anyone shed some light on this?

AFAICS, your program is invalid in two aspects, both of which gfortran
fails to detect:

1) Printing variables of a derived type with PPCs is forbidden. There
was a recent PR about this (PR47768) and I thought we had it fixed.

2) Your PPC 'get_special_area' is declared to expect a CLASS argument,
but then the procedure it points to has a TYPE argument. I should
re-check the standard on this, but I believe it is invalid. At least
this is the reason why you get wrong results (you pass a class
container to 'get_special_area', while 'get_my_area' needs a plain
variable of type 'rectangle').

Have you tried other compilers on this?

Cheers,
Janus



More information about the Fortran mailing list