Re: Allocatable Arrays As Outputs



Richard Maine wrote:
(snip)

The only thing solved by using pointer is to make the code
f90/f95-conforming, as allocatable dummy arguments require either f2003
or f95+TR. But most compilers do support the TR by now, and that does
not appear to be the OP's problem.

For some that might be enough reason.

I would say that changing to using a pointer here would not solve any
problems, but might add new ones (memory management problems and the
likelihood of errors both go way up with pointers compared to
allocatables).

(someone else wrote)
You also have to use the
save attribute in the subroutine to ensure the memory isn't lost when
the subroutine exits.

That is not so.
In fact, you are not allowed to use SAVE for dummy arguments at all.

The only reason I could think of for that statement was that
one might use a pointer dummy pointing to an ALLOCATABLE.
If one didn't understand that ALLOCATE could be used with pointer
variables, one might try that. It would seem even more error
prone than using pointers alone.

-- glen

.



Relevant Pages

  • Re: how DEALLOCATE statement works in f2003
    ... As there is no other pointer to those allocatables pointed ... deallocate anything allocatable _pointed_to_ by a pointer manually. ... way for you to create a memory leak with allocatables. ... The case involved also involved pointers, though, which I think is outside that dictum -- there is a memory leak, arising when an allocatable is deallocated, which happens because the allocatable contains pointers. ...
    (comp.lang.fortran)
  • Re: Derived type - valued function with pointer member.
    ... It was my understanding that pointers were needed to accomplish this. ... unless you embrace the common extension where ALLOCATABLES can be used. ... END TYPE mytype ... When I make the %vec's allocatable arrays instead, the program segfaults on calling vplus. ...
    (comp.lang.fortran)
  • Re: Question about a struct declaration
    ... typedef struct dummy *dummy; ... If want to use the type as a pointer, then hiding the fact that it is a pointer in a typedef is indeed a pretty useless idea. ... A classic example would be the interface of 'pthreads' library, where 'pthread_t', 'pthread_mutex_t' etc. might easily be pointers. ... work in case when you need to self-refer to the struct type from inside ...
    (comp.lang.c)
  • Re: DO or FORALL control ... is not declared locally ?
    ... of pointers for which there is an allocatable array equivalent". ... Many current uses of pointer components are for ... things that would more naturally be allocatables. ...
    (comp.lang.fortran)
  • Re: Copy-in/Copy-out
    ... they're not all that difficult: pointers to assumed shape dummies ... > provided both actual and dummy arguments have the target attribute. ... I do recall that one of the "secrets" to deciphering this was figuring ...
    (comp.lang.fortran)