Procedure Pointers: a first patch
Janus Weil
jaydub66@googlemail.com
Mon Jun 16 18:39:00 GMT 2008
Hi,
> Well, NULL() still does not work. As an example counts more than thousand
> descriptions, here comes one which works with g95 and ifort 11beta but fails
> with gfortran.
Ok, I fixed this problem with the NULL() initialization.
> The problem is that the line
>
> void (*<T5f>) (void) x;
>
> should be
>
> static void (*<T5f>) (void) x = 0B;
>
> program main
> implicit none
> call test(.true.)
> call test(.false.)
>
> contains
> integer function hello()
> print *, 'Hello'
> hello = 42
> end function hello
> subroutine test(first)
> logical :: first
> integer :: i
> procedure(), pointer :: x => null()
>
> if(first) then
> if(associated(x)) call abort()
> x => hello
> else
> if(.not. associated(x)) call abort()
> i = hello()
> if(i /= 42) call abort()
> end if
> end subroutine test
> end program main
This test case should work now. Besides some other things, I added the
following lines to trans-decl.c (get_proc_pointer_decl):
if (!sym->attr.use_assoc
&& (sym->attr.save != SAVE_NONE || sym->attr.data
|| (sym->value && sym->ns->proc_name->attr.is_main_program)))
TREE_STATIC (decl) = 1;
if (TREE_STATIC (decl) && sym->value)
{
/* Add static initializer. */
DECL_INITIAL (decl) = gfc_conv_initializer (sym->value, &sym->ts,
TREE_TYPE (decl), sym->attr.dimension, sym->attr.proc_pointer);
}
which I basically copied from other places. I hope it's ok like this
(at least it makes the test case work).
> Well, the problem is that the procedure pointer is passed as value and not
> as reference.
> See http://gcc.gnu.org/ml/fortran/2008-05/msg00299.html
I haven't really looked into this, and I'm not quite sure how to do
it. Any help is surely appreciated.
> I think the patch can be committed after:
> - NULL() is fixed
> - Procedure pointers are passed by reference
>
> Working procedure-pointer-returning functions were nice, but I think they
> can be deferred to a follow up patch. The same is true for the other smaller
> bugs.
Ok. Also I think procedure-pointer return values are rather exotic
(and I'm sure one can find a lot of other exotics which do not work
yet).
And given the fact that both ifort 11 beta and g95 seem to have
trouble with most of my (working) test cases, I guess this is quite ok
for an initial patch.
Cheers,
Janus
-------------- next part --------------
A non-text attachment was scrubbed...
Name: procptr136838.diff
Type: text/x-patch
Size: 20590 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20080616/3206a67e/attachment.bin>
More information about the Fortran
mailing list