My Modern Fortran book is now published

You can set custom lower bound also on an assumed-size array:

character(kind=c_char,len=1), intent(out) :: buf(0:*) 

In Fortran arrays are abstract and have bounds, whereas in C, char *buf is just an address. However the interoperability assumes that a Fortran fixed- or deferred-length character is interoperable with an array of characters. In addition, C uses the convention that a string (i.e. an array of characters) is terminated by the null character.

1 Like

I’d say that lumping together assumed-size arrays and assumed-length character scalars (both entities declared with an asterisk *) is not a good idea. The former entity bears no information about the true size of the actual argument while the latter - on the contrary, thus being more like assumed-shape array. I may not get all the linguistical nuances here but for me, a non-native English speaker, coining assumed term to all of those entities is quite unfortunate. If real :: tab(*) is to be called assumed-size, then real :: tab(:) or character(len=*) :: str might be called passed-shape/length?

BTW. I’m not sure whether the assumed-length is by any means official name of a dummy declared character(len=*) :: str - the F2018 Draft and Interpretation documents do mention assumed length and assumed-length in a few places but never in a defining context, rather as a reference to something obvious to the reader.

1 Like

Hello @milancurcic and congratulations for the book, I am happily getting back to fortran thanks to it :slight_smile: .
I would like to ask, are there any news about this future edition you were talking about? Are there concrete plans or is it still in the realm of ideas?

@msz95 said “I’d say that lumping together assumed-size arrays and assumed-length character scalars (both entities declared with an asterisk *) is not a good idea.”

Like many things in Fortran the reason for it is historical. Using * for both purposes dates back to Fortran 77, when assumed-shape arrays had not yet been invented. The syntax is kept unchanged so that few old programs won’t run with new compilers. Sometimes a new syntax is allowed as well as the old one, e.g. < as well as .lt.
The number of different uses of * in Fortran keeps rising: 19 in F95, 29 in F2018 unless I have missed some.

1 Like