[J3] BOZ in an array constructor
Bill Long
longb at cray.com
Sun Jul 7 18:01:28 EDT 2019
> On Jul 7, 2019, at 4:20 PM, Steven G. Kargl <kargl at troutmask.apl.washington.edu> wrote:
>
> On Sun, Jul 07, 2019 at 09:00:30PM +0000, Bill Long wrote:
>> C7109 allows this program - boz constants are specifically allowed
>> as the first argument to INT. And a ref to INT is allowed in an
>> initialization. And INT is elemental, so an array argument is OK.
>
> Well, yes, I agree a scalar BOZ is allowed as an argument to INT().
> The problem is the array constructor [z'1234', z'5678']. C7111
> from N2146.pdf states that z'1234' and z'5678' must have the
> same declared type and kind type parameter. BOZ is typeless, and
> a BOZ does not have a kind type parameter.
Correct. The form of the array constructor violates C7110.
>
> As a side note, is this legal "integer(4) :: i(2) = [42_8, z'42’]"
No. BOZ constants are not of type integer, so still violates C7110.
> The first ac-value is an INTEGER, and the second is BOZ. Is the
> BOZ first converted to INTEGER(8) to match 42_8, and then convert
> to INTEGER(4) on assignment?
ac-values in array constructors do not work that way..
>
>> I tried the program (changing the print statement to include a
>> Z format, so the result is easier to check) with 4 compilers, and
>> all worked fine and output the correct result. gfortran 8..3.0 was
>> included in the tests. I also tried 6.3 and that also worked. Are
>> you using a really old version of gfortran?
>
> It is an accident that gfortran works.
It is an “accident” that any of the 5 compilers I tried worked. They apparently all support the same extension.
Cheers,
Bill
> This is a result of a very
> old decision to have gfortran convert a BOZ to a type that satisfies
> the requirements of a BOZ in a DATA statement from Fortran 95 (even
> if the BOZ is not in a DATA statement and is not ultimatel an INTEGER).
>
> --
> steve
>
>>
>> Cheers,
>> Bill
>>
>>> On Jul 7, 2019, at 3:26 PM, Robert Corbett via J3 <j3 at mailman.j3-fortran.org> wrote:
>>>
>>> I think C7111 and C7112 are irrelevant. I think C7109 is the relevant constraint.
>>>
>>> Bob Corbett
>>>
>>>> On Jul 7, 2019, at 12:43 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. One would need to write
>>>>
>>>> program foo
>>>> integer(kind=4) :: i(2) = [int(z'1234'), int(z'5678')]
>>>> integer(kind=8) :: j(2) = [integer(8) :: int(z'1234'), int(z'5678')]
>>>> print *, i
>>>> end program foo
>>>>
>>>> The j(2) case could also be written as
>>>>
>>>> integer(kind=8) :: j(2) = [int(z'1234', 8), int(z'5678, 8)]
>>>>
>>>> Is my interpretation of C7111 and C7112 correct?
>>>>
>>>> --
>>>> Steve
>>>
>>
>> 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
>>
>>
>
> --
> Steve
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