Why are parens required around format strings?

AFAIK the outermost parentheses are representing the looping behaviour. When you run out of formatters e.g., print "(i0)", 1, 2, it will print 1 in one line and then because there are no more formatters, the last pair of parentheses are repeated as long as needed, adding a newline and 2.

If the outer parentheses were optional and left out, would this mean, that if there are no other parentheses, this loop doesn’t happen?

Besides, you can concatenate format strings since additional parentheses inside doesn’t interfere, e.g.,

character(*), parameter :: fmt_i = "(i0)"
character(*), parameter :: fmt_g = "(g0)"
print fmt_i, 42
print fmt_g, 3.14
print "(" // fmt_i // ", x, " // fmt_g // ")", 42, 3.14

Admittetly, you have to manually add the outer parentheses, but IMHO this isn’t that much of a problem. Most of the time you have to concatenate something in between anyway.

4 Likes