Documenting variable declaration and setting

The info found on the current site is a little poor.

It would be very helpful to add a special section about variable declaration and setting, presenting all possible ways to declare and set, for example, a real variable despite of being best practice or not, or with specific compiler support although hints would be added.

One goes through the Learn section and has to search to the web for additional info, too.

So what would you say is missing from the existing tutorial Variables — Fortran Programming Language. Could you be a bit more specific?

As for information that is compiler specific, I am not aware of any differences declaring and setting variables between the major compilers for Modern Fortran, although I will admit that I don’t closely follow all the available compiler extensions to the standard.

Ultimately however, compiler vendors are responsible for maintaining the docs for their compilers.

Hello Giannis (Γιάννη),

For example:

Some ways through a real number can be declared and initialised are:

use, intrinsic :: iso_fortran_env, only: sp=>real32, dp=>real64, qp=>real128

real :: r ! default
real(n) :: rn ! where n: 4|8|10|16
real(kind=n) :: rkn ! where n: 4|8|10|16
real(cc) :: rcc ! where cc: sp|dp|qp

r = 1 ! integer value coerced to real (not suggested)
rn = 1.
rkn = 1._n ! where n: 4|8|10|16
!rkn = 1_10 ! Wrong
rcc = 1._sp

This is a very simple example and not completed.

Perhaps, the best way is to academically interpret the Fortran technical specification by integrated practical examples. Note: Examples should not have semantics not yet taught.

The sections Setting up your OS and Building programs are very helpful although they are simple as required. One has to search on the web for additional info which is totally accepted since both sections are auxiliary to Fortran.

Quickstart tutorial should have, at least, links per paragraph to the corresponding chapter of the Fortran Language Manual for more info.

The Quickstart Tutorials offered by Fortran-lang, at least at this point, are exactly what’s on the label, short & quick demos to get someone to start using Fortran. I wouldn’t treat them as a complete, academic, learning resource. There are many great books and courses that aim to do just that Learn — Fortran Programming Language.

Now, for the specific demo you posted. I think it is a big hint to the user that iso_fortran_env offers named constants with names INT8, INT16, INT32, INT64, REAL32, REAL64 and REAL128. Just by looking at a single such name it should be clear to the user that these constants are not interchangeable and hence doing 1._real32 and 1._4 are two different things.

Given that understanding kinds in Fortran is not usually an entry level problem, this entire conversation has been deferred for the later section Floating Point Numbers — Fortran Programming Language. In that section you will also find a link to the great blog post from @sblionel “It Takes All KINDs” that goes into even more details.

I don’t think that is realistically possible for a few reasons. There is no available free copy of the Fortran Standard. The standardisation, like many other languages (C,C++) is done via ISO and hence you have to purchase the document from them ISO - ISO/IEC 1539-1:2018 - Information technology — Programming languages — Fortran — Part 1: Base language. You can find drafts to the Standard online and that is what most of us use.

Secondly, I would invite you to have a read of the Fortran Standard (or a draft). It is a technical document, it is not meant to be consumed by the average user, much less be part of a quickstart tutorial to the language. Providing references to the Standard would probably cause only confusion to a beginner.

2 Likes