11-167r2 To: J3 From: Nick Maclaren / Bill Long Subject: Interop TR: more on constraints Date: 2011 July 1 Reference: N1854, 11-167, 11-168r2, 11-175r2 Clean up of restrictions on what can be done with C descriptors. Edits to N1854: [13:8+] Move para 2 of 5.2.6 [19:36-38] to here. {{{Strictly, the following INTENT constraints do not belong in the TR, as they are more like a fix to the existing interoperability. C's rules on 'read-only' data and when data may be references are wildly different from Fortran's, and I believe that spelling Fortran's rules out is a good idea. There is already such wording in 5.2.5.1, so we could add: }}} [13:8++] Add the paragraph following the one moved by the previous edit: "The following restrictions apply if an object is pointed to by a formal parameter or actual argument that corresponds to a nonpointer dummy argument in a BIND(C) interface: * it shall not be modified if the Fortran dummy argument has the INTENT(IN) attribute; * it shall not be accessed before it is given a value if the Fortran dummy argument has the INTENT(OUT) attribute." [15:32-35] Replace: "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." by "It shall not point to a C descriptor that is pointed to by a formal parameter that corresponds to a Fortran actual argument." [16:19] Change "to the C descriptor established" to "to an established C descriptor". [17:12-15] Replace: "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." by "If /result/ points to a C descriptor that is pointed to by a formal parameter that corresponds to a Fortran actual argument, the attribute member shall not have the value CFI_attribute_assumed." [17:17] At the end of the source description, add "The corresponding values of the elem_len and type members shall be the same in the C descriptors pointed to by source and result." [18:9-12] Replace: "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." by "If /result/ points to a C descriptor that is pointed to by a formal parameter that corresponds to a Fortran actual argument, the attribute member shall not have the value CFI_attribute_assumed." [18:14] At the end of the source description, add "The corresponding values of the rank member shall be the same in the C descriptors pointed to by source and result." [19:12] At the end of the source description, add "If source is not NULL, the corresponding values of the elem_len, rank, and type, members shall be in same in the C descriptors pointed to by source and result." [19:33-41] Replace the remaining contents of section 5.2.6 by: A C descriptor shall not be initialized, updated or copied other than by calling the functions specified here. The following restrictions apply if a C descriptor 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 or unknown-size array; * its base_addr member shall not be accessed before it is given a value if the Fortran dummy argument is a pointer and has the INTENT(OUT) attribute. 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 will cause undefined behavior." All TR: Throughout the TR, replace "NULL" with "a NULL pointer" except in code examples and elsewhere NULL is needed.q