This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [Patch, Fortran, F08] PR45290: pointer initialization


> That looks perfectly valid, cf. below.
>
> - ? ?integer(c_int), dimension(:), pointer :: int_ptr
> - ? ?my_c_ptr = c_loc(int_ptr(0))
>
>
> Well, as written is is invalid - but change it to
>
> - ? ?integer(c_int), dimension(:), pointer :: int_ptr
> ALLOCATE(int_ptr(0:10))
> - ? ?my_c_ptr = c_loc(int_ptr(0))
>
>
> Then it is valid.


... which means that a through check for validity is very hard to do
at compile time, since it depends on the run-time value, right?



> Note: "int_ptr(0)" is not a pointer but "int_ptr(0)" is
> the first element of the array to which int_ptr points. That array is
> unnamed but has the TARGET attribute. If you want to have a named target,
> use:
>
> integer, target :: tg(0:10)
> - ? ?integer(c_int), dimension(:), pointer :: int_ptr
> int_ptr => ?tg
> - ? ?my_c_ptr = c_loc(int_ptr(0))
>
> In this case int_ptr(0) is the first element of "tg" and "tg" has the TARGET
> attribute.

Well, ok. I guess that is one way to look at it. However, if I apply
the same logic to your earlier pointer-init example ...


module m
 integer, target, save  :: t1
 integer, pointer :: p1 => t1
 integer, pointer :: p3 => p1
end module m

... then I'd say this is valid, too. p1 itself is a pointer, but the
thing that it points to is a target (namely t1). Therefore "p3 => p1"
is valid, since the object on the RHS has the TARGET attribute. Can we
agree on that?

Cheers,
Janus


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]