Some basic questions on Fortran

@Aman,

Welcome to the forum and for your interest in GSoC!

Interesting questions. If you remain interested in Fortran, please try to refer to Modern Fortran Explained as suggested above. You can consider Intel oneAPI toolkit with IFORT Classic compiler for Fortran in conjunction with that book: Intel releases oneAPI Toolkit, free, Fortran 2018 Or, the standard of course!

So as you have noted already, there is an ISO IEC Standard for Fortran similar to C and C++ and that there are quite a few compilers such as Intel IFORT, GCC gfortran, Cray HPE, NAG, IBM, etc. You will notice the standard consciously avoids getting into details on quite a few aspects but instead leaves them as processor (compiler) dependent mechanisms that then allow compilers to adopt suitable implementation designs as long as certain requirements involving actual argument and dummy argument association and storage association, etc. are met. Such aspects pertain to your questions 2 and 4.

Re: your question 2 in terms of calling mechanism, as you look into the possibilities in the standard with various situations of argument association with different arguments (parameters) including explicit-size and assumed-size arrays, assumed-shape arrays, polymorphic objects, arguments of VALUE or VOLATILE attributes, etc., you will notice it’s inappropriate to box Fortran as call by reference even if you find such an (erroneous) allegation in many places.

Re: question 3, note immutability in Fortran can be enforced via the PARAMETER attribute:

character(len=*), parameter :: string = "spiderman" !<-- string is immutable in this instance

Re: question 4 about CHARACTER object storage, refer to section 19.5.3.2 Storage sequence in the 18-007r1 document you linked above for some details.

Re: “can I access the character at index 1 (which is ‘s’) without using string(1:1)?” technically yes - see a convoluted approach below. The indexer facility (string(i:i)) is the most convenient way, I feel, to work with a substring in a given CHARACTER variable.

   character(len=:), allocatable, target :: string
   character(len=1), pointer :: s
   string = "spiderman"
   s => string
   print *, "string = ", string
   print *, "s = ", s
   s = "S"
   print *, "string = ", string
end 

C:\Temp>ifort s.f90
Intel(R) Fortran Intel(R) 64 Compiler Classic for applications running on Intel(R) 64, Version 2021.1.2 Build 20201208_000000
Copyright (C) 1985-2020 Intel Corporation. All rights reserved.

Microsoft (R) Incremental Linker Version 14.28.29337.0
Copyright (C) Microsoft Corporation. All rights reserved.

-out:s.exe
-subsystem:console
s.obj

C:\Temp>s.exe
string = spiderman
s = s
string = Spiderman

C:\Temp>

1 Like