Fortran compiler specific kind modifier.

Click For Summary
SUMMARY

The discussion centers on the differences in the "kind" modifier between the SilverFrost FTN95 compiler and the g95 compiler in Fortran. The SilverFrost implementation defines integer kinds as kind=1 for int8, kind=2 for int16, kind=3 for int32, and kind=4 for int64. In contrast, g95 defines them as kind=1 for int8, kind=2 for int16, kind=4 for int32, and kind=8 for int64. The g95 implementation aligns with the Fortran 95 standard, which does not specify a direct relationship between kind values and variable sizes, emphasizing the importance of using selected_int_kind for portability.

PREREQUISITES
  • Understanding of Fortran programming language
  • Familiarity with compiler differences, specifically SilverFrost FTN95 and g95
  • Knowledge of Fortran 95 standards regarding data types
  • Experience with the selected_int_kind function in Fortran
NEXT STEPS
  • Research the Fortran 95 standard documentation for data type specifications
  • Explore the selected_int_kind function and its usage in Fortran
  • Compare other Fortran compilers and their handling of kind modifiers
  • Investigate best practices for writing portable Fortran code
USEFUL FOR

This discussion is beneficial for Fortran developers, particularly those transitioning between different compilers, and anyone interested in ensuring code portability across Fortran implementations.

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.
 

Similar threads

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