Fortran Fortran compiler specific kind modifier.

Click For Summary
The discussion highlights a compatibility issue between the SilverFrost FTN95 and g95 Fortran compilers regarding the "kind" specifier for integer types. The SilverFrost implementation assigns kind values differently, with kind=3 corresponding to int32, while g95 uses kind=4 for int32. Users are encouraged to utilize the selected_int_kind function to ensure portability across different compilers, as the Fortran standard does not define a specific relationship between kind values and variable sizes. The g95 implementation is suggested to align more closely with the Fortran 95 standard compared to SilverFrost. Adopting standard practices will enhance code compatibility and portability.
uart
Science Advisor
Messages
2,797
Reaction score
21
Fortran compiler specific "kind" modifier.

I've recently switched over from the SilverFrost (Salford) FTN95 compiler to the open source g95 compliler. So far everything seems very compatible between the two compilers (as in the same source compiles without modification on either compiler) except for one thing. The "kind" specifier in the Silverfrost implementation seems to be different to that of the g95 implementation.

In the SF ftn95 implementation they use -
kind=1 : int8
kind=2 : int16
kind=3 : int32
kind=4 : int64.

Just now I went to compile a program that had some code like "integer (kind=3) :: i, j, k" and it told me that kind=3 was not a valid integer kind.

I've just made a few quick tests and it seems that g95 integer kinds are defined as follows -
kind=1 : int8
kind=2 : int16
kind=4 : int32
kind=8 : int64.

Can someone please confirm that the above is correct?

BTW. I'm suspecting that the g95 implementation is actually the correct fortran95 standard and the SF ftn95 is the one that's breaking standard.
 
Technology news on Phys.org
uart said:
BTW. I'm suspecting that the g95 implementation is actually the correct fortran95 standard and the SF ftn95 is the one that's breaking standard.
The standard doesn't specify the relation between the kind value of the size of the variable. Using hard-coded values for kind will lead to a program that is not portable. One has to use selected_int_kind.
 
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

  • · Replies 5 ·
Replies
5
Views
7K
Replies
11
Views
15K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 3 ·
Replies
3
Views
16K
  • · Replies 23 ·
Replies
23
Views
2K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 6 ·
Replies
6
Views
2K