[J3] [EXTERNAL] Re: VALUE attribute for assumed-shape in an interface with bind C

Vipul Parekh parekhvs at gmail.com
Mon Jan 10 19:05:42 UTC 2022


On Mon, Jan 10, 2022 at 12:09 PM Reuben D. Budiardja via J3 <
j3 at mailman.j3-fortran.org> wrote:

> .. I get that both assumed-size/shape are
> interoperable (without VALUE).
>
> I was responding to your earlier comment:
> "there are no other cases allowing VALUE for non-scalars, therefore this
> is not permitted."
> the former does not necessarily imply the latter. The former only means
> that "assumed-shape with VALUE" is not interoperable.
>
> Putting aside interoperability, I was arguing that if we want to
> disallow VALUE attribute for assumed-shape, it should be said so,
> perhaps in C867 or somewhere in the VALUE attribute section?
>

Hello Reuben,

Happy New Year!

Please see below - it does appear to me the standard does intend to allow
VALUE attribute with assumed-shape and that may be why constraint C867 or
anything else in the VALUE attribute section of the standard does NOT state
anything to exclude the use of assumed-shape with VALUE.

Rather the issue, as mentioned by Steve, seems to be the semantics around
interoperability with C.  It is section 18.3.6 Interoperability of
procedures and procedure interfaces in the current standard where no
interpretation is provided for nonscalar arguments with VALUE attribute.
Paragraph 2 in section 18.3.6 covers the procedures that are interoperable
and assumed-shape with VALUE is not among them which makes it not
interoperable.

Consider the following example where bind(C) clause is absent and thus
interoperability with C is not in effect:
module m
contains
   subroutine sub( a )
      integer, value :: a(:)
      print *, "In sub: size(a) = ", size(a), "; expected is 3"
      a = 0
   end subroutine
end module
   use m
   integer :: x(3)
   x = [ 1, 2, 3 ]
   call sub( x )
   print *, "x = ", x, "; expected is [ 1, 2, 3 ]"
end

Two processors I tried compile the code ok and help produce with the
following expected output:
 In sub: size(a) =  3 ; expected is 3
 x =  1 2 3 ; expected is [ 1, 2, 3 ]

I reckon the code conforms and it is a valid use case that the standard
intends to continue to support.

Apply bind(C) to the interface for sub in the code example above and both
the processors issue errors which seems consistent with section 18.3.6.

Regards,
Vipul
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20220110/c7bba872/attachment.htm>


More information about the J3 mailing list