This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: SIGSEV in user-defined elemental function
Hi Daniel,
Daniel Franke schrieb:
>> forrtl: severe (408): fort: (7): Attempt to use pointer T when it is
>> not associated with a target
>>
>
> which version of ifort do you use? Here, with v9.0, I get:
> $> ifort -g -warn all -check all main.f90 && ./a.out
> [empty line]
> $>
> Which is, what I expected.
>
And which I don't expect.
NAG f95 -C=all gives:
Reference to disassociated POINTER T
and ifort -check all (l_fc_c_9.1.040, 20061101) gives:
forrtl: severe (408): fort: (7): Attempt to use pointer T when it is not
associated with a target
The reason that the program crashes using gfortran, g95, NAG f95 and
sunf95 is simple:
You tell the compiler that the function "func" gets a variable "t".
If "t => null()" then accessing anything which is part of "t" is invalid.
And using associated you check "t%p".
(In principle, you need to check "associated(t)", which is not possible,
however, since "t" is not a pointer.)
The "associated(t%p)" problem has nothing to do with elemental function
nor with function as it is likely also to crash in the main program.
In addition, your are not allowed to pass NULLified actual arguments.
See:
http://groups.google.com/group/comp.lang.fortran/browse_thread/thread/f683d1a1202ad04a/
> I'm not sure how ELEMENTAL is implemented, but since the argument type of
> func() is not a pointer type but a reference, one can not try to avoid this
> segfault by
> ELEMENTAL LOGICAL FUNCTION func(t)
> TYPE(atype), INTENT(in) :: t
> IF (ASSOCIATED(t))
>
gfortran and ifort offer the extension "loc()" to access the address of
a variable. That way you could do
if(loc(t) /= 0)
Tobias