The difference between the symbol * 10 :: a and the symbol :: a (10) "

Trying to update my Fortran 90 knowledge for a project, I encountered some weirdness when using internal files. Consider a code example:

! ---- internal_file_confusion.f90 ----
program internal_file_confusion
  implicit none 

  character*40 :: string1
  character :: string2(40)

  write(string1, *) "Hello World 1"
  write(*,*) "string1 = ", string1

  write(string2, *) "Hello World 2"
  write(*,*) "string2 = ", string2

end program 

which when compiling with gfortrancrashes, writing to STDOUT

 string1 =  Hello World 1                          
At line 10 of file e:/Daten/tmp/fortran-training/internal_file_confusion.f90
Fortran runtime error: End of record

When declaring with a notation, an *lengtharray of characters can be used for internal notation, but not when declaring with a note name(length). In addition, I noticed that the designation is *lengthapparently only allowed for character arrays, while this is forbidden with an error message, e.g.

Error: Old-style type declaration INTEGER*40 not supported at (1)

for other data types.

What is the difference between these designations and why does this affect the use as internal files?

+4
1

character*40 :: string - 40

character(len=40) :: string 40

character :: string(40) - 40 1

character*40 :: string(40) - 40 40

character(len=40) :: string(40) - 40 40

, string2. string2(1) 1 . , .

( ). , ().

+7

Source: https://habr.com/ru/post/1613655/


All Articles