11-167 To: J3 From: Nick Maclaren Subject: Interop TR: more on constraints Date: 2011 June 07 Reference: N1854 Upon looking it over, I have come back to the current approach. I have also spotted a couple of other nasties that I had missed before. I believe that this covers Reinhold's and my points, and minimises the changes. I have also included minor fixes to CFI_establish, CFI_section and CFI_select_part which look like historical artifacts. A point raised by Reinhold and Bill is that we should define rules that apply to C interfaces as well as ones between C and Fortran. I don't see any practical way of doing that, without the structure of a BIND(C) interface to tie things to. There is a significant overlap with 5.2.7, but I think that it better to keep them separate, to avoid some extremely messy wording. {{{ The following deletions in 15:32-35, 17:12-15 and 18:9-12 are moved to 5.2.6 in an expanded form. }}} [15:32-35] Delete "It shall not point to a C descriptor that describes an object that is described by a C descriptor pointed to by a formal parameter that corresponds to a Fortran dummy argument. It shall not point to a C descriptor that describes an allocated allocatable object." [16:19] Change "to the C descriptor established" to "to become a valid C descriptor". [17:12-15] Delete "It shall not point to a C descriptor that describes an object that is described by a C descriptor pointed to by a formal parameter that corresponds to a Fortran dummy argument. It shall not point to a C descriptor that describes an allocated allocatable object." [17:29] Change "to the C descriptor established" to "to become a valid C descriptor". [18:9-12] Delete "It shall not point to a C descriptor that describes an object that is described by a C descriptor pointed to by a formal parameter that corresponds to a Fortran dummy argument. It shall not point to a C descriptor that describes an allocated allocatable object." [18:30-31] Change "to the C descriptor established" to "to become a valid C descriptor". {{{ In the following, I have referred to a dummy argument when it might be more natural to refer to an actual argument. The reason for that is that I am referring to the interface, which Fortran requires to be the same as any procedure definition. }}} [19:33-35] Delete "A C descriptor that is pointed to by a formal parameter that corresponds to a Fortran dummy argument with the INTENT(IN) attribute shall not be updated." [19:36] After "a C descriptor", add "that is pointed to by a formal parameter or actual argument that corresponds to a dummy argument in a BIND(C) interface". [19:41+] Add the new paragraphs: "The following restrictions apply to a C descriptor that is pointed to by a formal parameter or actual argument that corresponds to a dummy argument in a BIND(C) interface: * It shall not be modified if either the Fortran dummy argument has the INTENT(IN) attribute or the descriptor is for an assumed-shape array. * No modification shall have the effect of changing the rank, type or attribute members. The elem_len member shall not be changed unless the descriptor is for a character type. * If it has the ALLOCATABLE attribute, it shall be modified only by calling the functions CFI_allocate and CFI_deallocate." * If it has the POINTER attribute, it shall be modified only by calling the functions CFI_allocate, CFI_deallocate, CFI_section, CFI_select_part and CFI_setpointer. NOTE In this context, modification refers to any change to the location or contents of the descriptor, including establishment and update. The intent of these restrictions is that C descriptors remain intact at all times they are accessible to an active Fortran procedure, so that the Fortran code is not required to copy them. C programmers should note that doing things with descriptors that are not possible in Fortran may well confuse compilers and cause misbehaviour; the restrictions here exclude only the more obvious issues."