ISO/IEC JTC1/SC22/WG5 N1539 Storage size Richard Maine This is a revision of N1531 based on comments about it. This paper proposes that we replace NUMERIC_STORAGE_SIZE and CHARACTER_STORAGE_SIZE with an intrinsic function that can inquire about the size of any storage unit defined by the standard. I. Why do anything? In response to a public comment, paper J3/03-108r3 added three new named constants to ISO_FORTRAN_ENV. I have no objection to the addition of FILE_STORAGE_SIZE. However, for the other two, I strongly feel that this is something that we should do correctly if we are going to do it at all. Many, if not most, implementations already have a similar function. I have avoided the most common current names for it specifically to avoid potential conflicts in points of detail .... and that allows me to do one thing in what I consider to be a more robust way (we will return the size in bits instead of in octets). With NUMERIC_STORAGE_SIZE and CHARACTER_STORAGE_SIZE we would be adding a new feature that not only is obsolete now - it was obsolete two revisions of the standard ago. Those constants constants would have been adequate for f77. As of f90, they are woefuly inadequate. Why are we adding new features to f2k that support only f77 code and are all but useless for code that follows most style recommendations for f90 code? Are we prepared to explain our answer to that question when it gets asked by users, as it most certainly will be? When that happens, don't expect me to defend the feature. I do not find the argument that "this is what someone asked for" to be very convincing. People ask for lots of things that they don't get. We need to apply our best judgement in answering requests - not just limit the answers to yes or no. In this case, a solution that I consider good is quite doable. We can do the job in a way that provides both the requested functionality and also useful for newer coding styles. It isn't particularly difficult to do that. If we don't think this feature is worth the small amount of work to do that way, or if a majority thinks that it is harder than I do, then I don't think we should do it at all. II. Design considerations and alternatives This function could be added either as an intrinsic or as a module procedure in ISO_FORTRAN_ENV. I came down slightly on the side of doing it as an intrinsic, but it was a close call. The edits below are for that approach. If a majority finds it more appropriate in the module, that is an easy change and one I'd find acceptable. Other choices for the function name would also be acceptable. The proposed function allows array arguments, but always returns the size of a scalar of the type. The standard adequately defines the storage requirements for arrays in terms of those for scalars, so I see no need for array-related functionality in this function. I consider the proposed function similar to the LEN intrinsic in this regard (LEN accepts array arguments, but returns the length of an element rather than the length of the whole array). The edits below delete the NUMERIC_STORAGE_SIZE and CHARACTER_STORAGE_SIZE constants, because the function is more general. If one wanted to have both the constants and the function, I wouldn't object too strongly. That wouldn't be my first choice, but it is well within bounds that I'd consider reasonable as a compromise. The allowable types of the argument are restricted to those types for which the standard already defines a storage size concept; this is all types that can be involved in storage association. In addition to the restrictions below, Van also suggested disallowing derived types with length type parameters (we do want to allow character though, so it would be important that this restriction be only on derived types). It appears to me that the draft already defines a storage unit for derived types with length type parameters and that therefore such a restriction is unnecessary here. It is possible that this is an error in the existing draft; if so, and if that is corrected, then I'd agree that such a restriction is appropriate here. I think the real question there is whether the existing draft is acceptable in defining such storage units. That is not fundamentally a question about this intrinsic; the intrinsic should just inquire about whatever the rest of the draft defines. It appears to me that the existing draft is in error in that it disallows BIND(C) types in storage association contexts. I believe that to be an unintentional oversight based on thinking that BIND(C) is a form of SEQUENCE. I think it quite important to be able to inquire about the size of BIND(C) types, so I have allowed them here, in anticipation of this oversight in the existing draft being fixed. If the committee truly believes that BIND(C) types should not be allowed in storage association contexts, then the "or have the BIND attribute" in the edits below should be deleted (but I really think that would be a mistake). For simplicity, this proposal depends on the declared type instead of the dynamic type. It turns out that the other restrictions rule out all the cases where there can be a difference, so this could be written either way (and could be changed in the future without incompatibilities). I'm willing to go either way on that. If this is changed to allow polymorphic arguments (in which case there could be a difference), we should still disallow unlimitted polymorphic arguments (becase they would need additional restrictions to make them work). I think the KIND argument unnecessary, but it was suggested and I go along with adding it for consistency. I'd also go along with deleting it. III. Edits [127:41+] Add list item (4a) the inquiry function STORAGE_SIZE, [298:19+] Add line "STORAGE_SIZE (X [, KIND]) Storage size in bits" [356:1+] Add section 13.7.115a STORAGE_SIZE (X [, KIND]) Description. Returns the storage size in bits for a nonpointer nonallocatable scalar of the declared type of X. Class. Inquiry function. Arguments. X may be of intrinsic or derived type. It shall not be polymorphic. If it is of derived type, that type shall be a SEQUENCE or interoperable type and shall have no allocatable ultimate components. If its type has any deferred type parameters, it shall be a pointer that is associated or an allocatable object that is allocated. It may be a scalar or an array. KIND (optional) shall be a scalar integer initialization expression. Result Characteristics. Integer scalar. If KIND is present, the kind type parameter is that specified by the value of KIND; otherwise, the kind type parameter is that of default integer type. Result Value. The result value is the size in bits of the storage unit (16.4.3.1) in a storage association context for a nonpointer nonallocatable scalar with the declared type and type parameters of X. Example. STORAGE_SIZE(1.0) returns the number of bits in the numeric storage unit. [417:36-38] "The sizes...(13.8.2.3)" -> "The size of the file storage unit is given by the constant FILE_STORAGE_SIZE (13.8.2.3.3). The sizes of the character storage unit, numeric storage unit, and unspecified storage units can be determined using the intrinsic function STORAGE_SIZE (13.7.115a)." [362:28-33] Delete sections 13.8.2.3.1 and 13.8.2.3.2. {This assumes that 13.8.2 has been simplified as described in part 1 of my paper titled ISO_FORTRAN_ENV. If that isn't done, then other trivial changes are needed in the sentence that forms the body of 13.8.2.3, and the 13.8.2.3.3 section heading should probably be deleted (or promoted).