j3-fortran / fortran_proposals

Proposals for the Fortran Standard Committee
175 stars 14 forks source link

Allow character array constructors with variables of different LEN #301

Open Beliavsky opened 1 year ago

Beliavsky commented 1 year ago

Some people, including me, have wished that a character array constructor with variables of unequal length

["a", "bb", "ccc"]

which is currently illegal, were treated as a character array where the LEN equals that of the element with the largest LEN, so that the above is equivalent to

["a ", "bb ", "ccc"]

or

[character (len=3) :: "a", "bb", "ccc"]

klausler commented 1 year ago

As complete implementations of the language must already be capable of evaluating every effective item in an array constructor into an expanding pool of dynamic memory in worst case scenarios -- think about an array constructor with implied DO loops with dynamic bounds, or items that are function results of dynamic shape -- this request shouldn't require too much extra work in a compiler or its runtime support library. If you could whip up a prototype in an open-source compiler as a demonstration, you might find support for this in other compilers easy to come by.

certik commented 1 year ago

I agree with @klausler I think this doesn't seem difficult to implement.