j3-fortran/fortran_proposals

Allow character array constructors with variables of different LEN

Opened this issue · 2 comments

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"]

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

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