[J3] BOZ in an array constructor

Robert Corbett rpcorbett at att.net
Mon Jul 8 09:28:36 EDT 2019


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'

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



More information about the J3 mailing list