Fortran compiler specific kind modifier.

In summary, there is a difference in the "kind" specifier between the SilverFrost FTN95 compiler and the open source g95 compiler. The SilverFrost implementation uses kind values 1, 2, 3, and 4 for int8, int16, int32, and int64 respectively, while the g95 implementation uses values 1, 2, 4, and 8. This difference may be due to the g95 implementation following the Fortran95 standard, while the SilverFrost implementation may not be in line with the standard. Additionally, hard-coding kind values can lead to non-portable programs and the use of selected_int_kind is recommended instead.
  • #1
uart
Science Advisor
2,795
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
  • #2
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.
 

1. What is a "kind" modifier in a Fortran compiler?

A "kind" modifier in a Fortran compiler is a way to specify the size and precision of a data type. It allows the programmer to choose a specific kind of integer, real, or complex number that best suits their needs.

2. How is a "kind" modifier specified in a Fortran program?

A "kind" modifier is specified by adding a letter or number after the data type declaration. For example, "integer(4)" specifies a 4-byte integer and "real(8)" specifies an 8-byte real number.

3. Why is it important to use a "kind" modifier in a Fortran program?

Using a "kind" modifier allows for greater control over the precision and size of data types, which can be crucial for scientific calculations. It also ensures consistency across different compilers and platforms.

4. Can a "kind" modifier be used with user-defined data types?

Yes, a "kind" modifier can be used with user-defined data types. This allows for even more flexibility and customization in the programming code.

5. Are there any potential drawbacks to using a "kind" modifier in a Fortran program?

One potential drawback is that using a specific "kind" modifier may limit the portability of the program to other compilers or platforms. It is important to choose a "kind" modifier that is widely supported.

Similar threads

  • Programming and Computer Science
Replies
11
Views
14K
  • Programming and Computer Science
Replies
10
Views
2K
  • Programming and Computer Science
Replies
4
Views
3K
  • Programming and Computer Science
Replies
6
Views
3K
  • Programming and Computer Science
Replies
12
Views
3K
  • Programming and Computer Science
Replies
23
Views
2K
  • Programming and Computer Science
Replies
4
Views
15K
  • Programming and Computer Science
Replies
5
Views
1K
  • Programming and Computer Science
Replies
6
Views
1K
Back
Top