To: J3 J3/21-134r2 From: Malcolm Cohen Subject: Interp F18/026 C_SIZEOF argument Reference: 20-151 Date: 2021-June-25 /INTERP subgroup agrees that all the examples in the interpretation request should be conforming, but is not in complete agreement for arguments with the POINTER or ALLOCATABLE attribute. There is an argument that the POINTER attribute should not be allowed, because "C programmers expect sizeof(a pointer) to return the size of the pointer itself, not the size of its target". A similar (but weaker) argument applies to the ALLOCATABLE attribute, which has no direct analogue in C, but is somewhat like a kind of pointer. The counter-argument is that (1) sizeof(dummy array) in C gives you the size of a pointer, not the size of the array, so C_SIZEOF is sufficiently different from sizeof in C that this is not a problem. (2) For a POINTER X, prohibiting the POINTER attribute in C_SIZEOF would make C_SIZEOF(X) invalid, but C_SIZEOF((X)) would remain valid. This would be irregular. Straw Vote: (a) Permit POINTER arguments to C_SIZEOF (as written below); (b) Prohibit POINTER arguments to C_SIZEOF; (u) Undecided. ---------------------------------------------------------------------- NUMBER: F18/026 TITLE: C_SIZEOF argument DEFECT TYPE: Erratum STATUS: J3 consideration in progress QUESTION: Consider the example SUBROUTINE test(b) USE iso_c_binding REAL(c_double) b(:),a(SIZE(b)) PRINT *,c_sizeof(a) ! A PRINT *,c_sizeof(b) ! B PRINT *,c_sizeof(a(::2)) ! C PRINT *,c_sizeof(a+1) ! D PRINT *,c_sizeof(1.0_c_double) ! E END SUBROUTINE 18.2.3.7 C_SIZEOF (X) states "X shall be an interoperable data entity..." According to that, the reference to C_SIZEOF marked A is valid, as A is interoperable (an explicit-shape array of interoperable type and type parameters). And the reference marked B is invalid, as only explicit-shape arrays and assumed-size arrays are interoperable, thus assumed-shape arrays are definitely not. For the references at C and D, the standard seems to be silent on the matter of whether they are interoperable. It is clear for named variables, but although subobject designators can denote variables, they are not names, and expressions are not variables at all. Being silent implies non-conformance as no interpretation is established. The reference at E also appears to be non-conforming, as the standard specifies no criteria for interoperability of expressions. However, the description of the result of C_SIZEOF only makes use of the interoperability of the type and type parameters. Are these references intended to be conforming? If not, should the standard be clarified to say that X shall be an interoperable named variable? ANSWER: Yes, these references were all intended to be conforming. An edit is supplied to correct this mistake. EDIT to 18-007r1: [473:27] 18.2.3.7 C_SIZEOF (X), p3 Argument, Change "an interoperable data entity that is not" to "of interoperable type and type parameters, and shall not be", making the whole paragraph read: "Argument. X shall be of interoperable type and type parameters, and shall not be an assumed-size array or an assumed-rank array that is associated with an assumed-size array." {Loosen the requirements.} SUBMITTED BY: Malcolm Cohen HISTORY: 21-134 m224 Submitted 21-134r1 m224 Revised 21-134r2 m224 Revised again ----------------------------------------------------------------------