To: J3 J3/19-132 From: Vipul S. Parekh Subject: int-literal-constant is also boz-literal-constant Date: 2019-February-08 References: none Introduction ------------ 18-007r1 states in R708 "int-literal-constant is digit-string[_kind-param]. In addition, C7109 (R764) has, "A boz-literal-constant shall appear only as a data-stmt-constant in a DATA statement, or where explicitly allowed in 16.9 as an actual argument of an intrinsic procedure." This effectively makea an integer literal in Fortran a decimal constant which is unlike several other programming languages employed in industry where an integer literal can also be a hexadecimal or octal or binary constant. Engineers, technologists, and scientists who often have to work with various different programming languages in industry find this constraint C7109 limiting in their pursuit of rapid and succint codes in Fortran which need to interoperate with software components in other languages whether they be database scripts or user-interfaces or web services or data analysis environments. Limitation of C7109 is felt acutely when the same values of integer literal constants have to be utilized in different interoperating software components but where the source format of values is something other than decimal (e.g., hex) and when there is an appreciable amount of data to be handled. Formal Requirements ------------------- Coders want to be able to represent integers as hexadecimal or octal or binary values toward the following (but not limited to this) set of use cases: a) integer named constant and variable definition contexts integer[(kind=kind_param), parameter :: ] x = Z"FF"[_kind_param] integer[(kind=kind_param) :: ] n . n = O"034" b) construct an array of integers to aid certain numeric processing tasks, often as named constants: integer[(kind=xx), parameter :: ] a(*) = [ integer[(kind=xx)] :: Z"d76aa478", Z"e8c7b756", .. & ! dozens of continuation lines .. ] Note: per current standard, a coder may arrive after several stumbles at code such as integer(I8), parameter :: foo(*) = [ int(Z"d76aa478",I8), & int(Z"e8c7b756", I8), .. & ! dozens of continuation lines & .. ] c) define enumerations in a manner consistent with that in the companion processor: enum, bind(C) enumerator :: PARAM_FOO = B"2000" ! in C, 0x2000 enumerator :: PARAM_BAR = B"4000" ! in C, 0x4000 end enum d) utilize logical expressions that are more readable given a context: if ( buffer > Z"3F" ) then ! do something end if e) SELECT CASE constructs which are more readable given a context: select case ( switch ) case ( Z"FFFF" ) .. case ( Z"FFFE" ) .. .. end select Formal Specification -------------------- Under Numeric intrinsic types, Integer type, where any integer value can be represented as a signed-int-literal-constant: int-literal-constant is digit-string [ _ kind-param ] boz-literal-constant [ _ kind-param ] Syntax ------ See examples above with use cases listed with the Formal Requirements Edits -----