To: J3 10-225 From: Bill Long Subject: Interop TR: Requirement R9d Date: 2010 October 07 Reference: 10-165r2, N1820, 10-007 Discussion: Requirement R9d in N1820 is: INTENT(OUT) ALLOCATABLE dummy arguments are permitted in a BIND(C) routine. It is the responsibility of the processor to deallocate the actual argument in any cross-language call. It is not required for the processor to handle this in C-to-C calls. There are three possible cases. Case 1: If the caller is a Fortran program unit, then this text of paragraph 6 of 6.7.3.2 'Deallocation of allocatable variables' in 10-007: "When a procedure is invoked, any allocated allocatable object that is an actual argument corresponding to an INTENT (OUT) allocatable dummy argument is deallocated.." clearly already requires the deallocation. Case 2: If the caller is a C function and the callee is written in Fortran, there is a clear expectation that the argument will be deallocated. Stating this expectation is the intent of R9d. Case 3: If the caller and callee are C functions, it is outside the scope of the TR to require that the C compiler generates the deallocation code. The required deallocation is done by extra code inserted by the compiler. The simplest implementation is to include the code in the callee, since this involves only one instance of the code, rather than generating separate code at each call site. This implementation would automatically cover Case 2. Case 1 effectively requires that the deallocation be done on the caller side for a BIND(C) callee, since there is no way to know, in general, whether the callee is written in Fortran or some other language. If the caller does the deallocation, and the callee is a Fortran procedure, the deallocation coded there will have no additional effect because the argument is not allocated. Since the thrust of R9d is essentially a message to implementors, it will be included in the TR as a Note. Edits to 10-165r2: [5:12+] After Note 3.1 in 3.3 'Argument association', add new Note: "NOTE 3.2 INTENT(OUT) ALLOCATABLE dummy arguments are permitted in a BIND(C) routine. It is the responsibility of the processor to deallocate the actual argument if either the calling or called procedure is a Fortran program unit. It is not required for the processor to handle this if neither the calling nor called procedure is a Fortran program unit."