[J3] BOZ in an array constructor
Bill Long
longb at cray.com
Mon Jul 8 11:48:13 EDT 2019
> On Jul 8, 2019, at 8:28 AM, Robert Corbett via J3 <j3 at mailman.j3-fortran.org> wrote:
>
> Everything you want to do in paper 19-132 can be done in Fortran 2018. Yes, you need to use the type conversion functions, which involves a bit of extra writing. There are good reasons for requiring explicit use of the type conversion functions.
>
> As Malcolm pointed out, different compilers treat BOZ constants differently. Some compilers treat BOZ constants as integers, while others treat them as uninterpreted bit strings. Consider the (nonstandard) statement
>
> X = Z’3F800000'
This assignment is currently disallowed, because boz constants are not of a numeric type. But if, as with the BITS proposal, it were allowed, the obvious way to do it is to use the same rules that apply to any implied type conversion (Table 10.9) on assignment, which is to apply the type conversion function for the type of the variable, i.e.
X = REAL(Z’3F800000’, KIND(X))
As the rules for a boz argument to REAL are already standardized, the main change to the standard needed for this to be legal is to not disallow it.
Cheers,
Bill
>
> where X is a real variable. One compiler might produce code that assigns X the value 1065353216.0, while another might produce code that assigns X the value 1.0. I have seen both behaviors. The statement can be made standard conforming using a type conversion function. Either
>
> X = INT(Z'3F800000')
>
> or
>
> X = REAL(Z'3F800000')
>
> indicates the programmer's intended meaning. It does so without requiring compilers to change their behavior for existing nonstandard code.
>
> Oracle's Fortran team received requests for CHAR and TRANSFER to be extended to accept BOZ constants. IIRC, the Oracle compiler allows CHAR to accept BOZ constants as the first argument.
>
> Bob Corbett
>
>> On Jul 7, 2019, at 9:32 PM, Vipul Parekh via J3 <j3 at mailman.j3-fortran.org> wrote:
>>
>> On Sun, Jul 7, 2019 at 3:44 PM Steven G. Kargl via J3
>> <j3 at mailman.j3-fortran.org> wrote:
>>>
>>> gfortran's handling of BOZ is rather broken, and I'm
>>> currently investigating several fixes. In writing
>>> a test program (assuming kind = 4 and 8 are valid), I
>>> came up with
>>>
>>> program foo
>>> integer(kind=4) :: i(2) = int([z'1234', z'5678'])
>>> integer(kind=8) :: j(2) = int([integer(8) :: z'1234', z'5678'])
>>> print *, i
>>> end program foo
>>>
>>> It seems to me C7111 prevents the i(2) case and C7112 prevents
>>> the j(2) case. ..
>>
>> Steve,
>>
>> Just fyi: see paper 132 from the J3 meeting 218 during Feb 11-15 2019:
>> https://j3-fortran.org/doc/year/19/19-132.txt
>>
>> Regards,
>> Vipul Parekh
>
Bill Long longb at cray.com
Principal Engineer, Fortran Technical Support & voice: 651-605-9024
Bioinformatics Software Development fax: 651-605-9143
Cray Inc./ 2131 Lindau Lane/ Suite 1000/ Bloomington, MN 55425
More information about the J3
mailing list