What does `CHARACTER*(*)` mean?

I came across character*(*) in: https://github.com/Reference-LAPACK/lapack/blob/122506cd8b6ce050a200920c3d4c0b153b150fd8/SRC/xerbla.f#L79, what does it mean exactly?

I am familiar with the star notation, where for example in gfortran the declaration real*8 means real(kind=8), although in the former the 8 means the number of bytes, while in the latter it is a compiler specific kind designator (in gfortran they happen to both be 8 for double precision).

My understanding is that character*10 means character(len=10).

What does character*(*) mean?

From experimenting with gfortran it seems character*(*) means the same as character(len=*), which is the same as character(*), in other words, the extra star * in character*(*) is superfluous. Is that the case?

From further experimenting, character(*, kind=c_char) is allowed, but character*(*, kind=c_char) is not, which leads me to believe that character*(*) is a workaround for character** (which does not parse), in other words, it’s the length of the character, size * bytes. It is just a coincidence that the more modern approach is to use character(len=*, kind=c_char) and that it looks similar.

You are looking for section 7.4.4 of Fortran 2018.

R721 char-selector    is length-selector

R722 length-selector   is
                       or * char-length [ , ]

R723 char-length       is ( type-param-value )
                       or int-literal-constant

R701 type-param-value  is scalar-int-expr
                       or *
                       or :

An asterisk as a type-param-value specifies that a length type parameter is an assumed type parameter.
1 Like

This is a weird part of Fortran syntax that dates to F77. You can say either:


Even more weird, you can do this:


and the (*) will take precedence. See in 18-007r1.

The CHARACTER* form is deprecated.

1 Like

Yes, character*( * ) is an archaic form that means the same as character( * ).

1 Like

Thank you @kargl, @sblionel and @billlong. Everything is clear now.