To: J3 J3/21-102r1 From: R. Bader & Bill Long Subject: CFI_setpointer interpretation request F18/024 Date: 2021-February-28 Reference: 18-007r1 ---------------------------------------------------------------------- NUMBER: F18/024 TITLE: CFI_setpointer with result a deferred length character KEYWORDS: C interoperability DEFECT TYPE: Erratum STATUS: Submitted 1. Description of the issue Section 18.5.5.9 "The CFI_setpointer function" states in para 2 that "If source is not a null pointer, the corresponding values of the elem_len, rank, and type members shall be the same in the C descriptors with the addresses source and result." The function can therefore not work correctly if the "result" parameter is a descriptor address for a deferred-length character entity coming in from Fortran, because the elem_len value is not available. Manual updates to result->elem_len are prohibited by 18.6 para 1. The text at [478:21] specifically allows interoperable interfaces with a dummy argument of type CHARACTER that has deferred character length, so setting a pointer within C of this nature to be associated with a CHARACTER pointer of specified element length should be allowed. Within Fortran CHARACTER(len=4), TARGET :: source CHARACTER(len=:), POINTER :: result result => source will work just fine, so this surely is a defect in the current specification. 2. Suggested resolution For the case of a character pointer in a call to CFI_setpointer, - permit result->elem_len having a different value than source->elem_len if the source and result are descriptors for a data entity of type CHARACTER and result has a deferred length, and - for this case, enforce overwriting result->elem_len with the value of source->elem_len. 3. Suggested edits against 18-007r1 In 18.5.5.9 The CFI_setpointer function - [491:27] In the description of the source formal parameter, second sentence, delete "elem_len, ". - [491:28+] In the description of the source formal parameter, after the second sentence add new sentence: "If source is not a null pointer and the C descriptor with the address result does not describe a deferred length character pointer, the corresponding values of the elem_len member shall be the same in the C descriptors with the addresses source and result." - [491:31] In the first sentence of paragraph 3, "Description" replace "base_addr and dim" by "base_addr, dim and possibly elem_len". - [491:38] At the end of the second bullet point of paragraph 3, "Description", add new sentence; "If the C descriptor with the address result describes a character pointer of deferred length, the value of its elem_len member is set to source->elem_len". SUBMITTED BY: Reinhold Bader HISTORY: 21-102r1 m223 F18/024 Submitted ----------------------------------------------------------------------