# Type component with len attribute must be default integer kind

**URL:** https://fortran-lang.discourse.group/t/type-component-with-len-attribute-must-be-default-integer-kind/2139
**Category:** Help
**Created:** [October 22, 2021, 4:47pm UTC](https://fortran-lang.discourse.group/t/type-component-with-len-attribute-must-be-default-integer-kind/2139 "2021-10-22T16:47:32Z")
**Posts on this page:** 18
**Page:** 1

<div class="post-metadata">

### Author: ![fortran4r](https://avatars.discourse-cdn.com/v4/letter/f/9de0a6/32.png) [@fortran4r](https://fortran-lang.discourse.group/u/fortran4r)
#### Post date: [October 22, 2021, 4:47pm UTC](https://fortran-lang.discourse.group/t/type-component-with-len-attribute-must-be-default-integer-kind/2139/1 "2021-10-22T16:47:32Z")

</div>

I need to create a parameterized derived type that contains two long arrays.

```auto
type my_type(n)
    integer(8), len :: n
    real(8) :: a(n) 
    real(8) :: b(n) 
end type

```

GFortran gives me this error message: component with LEN attribute must be default integer kind(4). How should I solve this issue?

I can work it around with allocatable arrays:

```auto
integer(8) :: n
  
type my_type
  real(8), allocatable :: a(:) 
  real(8), allocatable :: b(:) 
end type
  
type(my_type) :: x
      
allocate(x%a(n))
allocate(x%b(n))

```

---

<div class="post-metadata">

### Author: ![themos](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/themos/32/521_2.png) [@themos](https://fortran-lang.discourse.group/u/themos)
#### Post date: [October 22, 2021, 5:38pm UTC](https://fortran-lang.discourse.group/t/type-component-with-len-attribute-must-be-default-integer-kind/2139/2 "2021-10-22T17:38:41Z")

</div>

It’s probably better to steer clear of PDTs if you are going to be using mainly gfortran.

---

<div class="post-metadata">

### Author: ![mecej4](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/mecej4/32/855_2.png) [@mecej4](https://fortran-lang.discourse.group/u/mecej4)
#### Post date: [October 22, 2021, 6:22pm UTC](https://fortran-lang.discourse.group/t/type-component-with-len-attribute-must-be-default-integer-kind/2139/3 "2021-10-22T18:22:39Z")

</div>

Does the LEN parameter have to be INTEGER(8)? Or would INTEGER(4) suffice?

---

<div class="post-metadata">

### Author: ![fortran4r](https://avatars.discourse-cdn.com/v4/letter/f/9de0a6/32.png) [@fortran4r](https://fortran-lang.discourse.group/u/fortran4r)
#### Post date: [October 22, 2021, 6:23pm UTC](https://fortran-lang.discourse.group/t/type-component-with-len-attribute-must-be-default-integer-kind/2139/4 "2021-10-22T18:23:24Z")

</div>

> [@mecej4](#):
>
> Does the LEN parameter have to be INTEGER(8)?

Yes. I work with super long arrays.

---

<div class="post-metadata">

### Author: ![FortranFan](https://avatars.discourse-cdn.com/v4/letter/f/96bed5/32.png) [@FortranFan](https://fortran-lang.discourse.group/u/FortranFan)
#### Post date: [October 22, 2021, 7:17pm UTC](https://fortran-lang.discourse.group/t/type-component-with-len-attribute-must-be-default-integer-kind/2139/5 "2021-10-22T19:17:10Z")

</div>

> [@fortran4r](#):
>
> … GFortran gives me this error message …

@fortran4r , you may want to reconsider your use of a hard-wired number such as `8` for KINDs of intrinsic types.

This is more for any FOSS volunteer with GCC/gfortran willing to work in PDTs: the following snippet conforms and a standard-conforming compiler should help produce the output as shown:

```Fortran
   use, intrinsic :: iso_fortran_env, only : int64
   integer, parameter :: I8 = selected_int_kind( r=10 )
   type :: t1(n)
      integer(int64), len :: n = 0
   end type
   type :: t2(n)
      integer(I8), len :: n = 0
   end type
   type(t1) :: foo
   type(t2) :: bar
   print *, "kind(t1%n) = ", kind(foo%n)
   print *, "kind(t2%n) = ", kind(bar%n)
end

```

> kind(t1%n) = 8  
> kind(t2%n) = 8

---

<div class="post-metadata">

### Author: ![FortranFan](https://avatars.discourse-cdn.com/v4/letter/f/96bed5/32.png) [@FortranFan](https://fortran-lang.discourse.group/u/FortranFan)
#### Post date: [October 22, 2021, 9:02pm UTC](https://fortran-lang.discourse.group/t/type-component-with-len-attribute-must-be-default-integer-kind/2139/7 "2021-10-22T21:02:33Z")

</div>

> [@kargl](#):
>
> any compiler compiled the code most recently posted here, the compiler is likely broken. Please report bugs to the appropriate vendors.

“the code most recently posted here” has been fixed. There was a markdown error, new line was missing following “‘’''Fortran” and it omitted the first line that had the ‘use’ statement.

---

<div class="post-metadata">

### Author: ![msz59](https://avatars.discourse-cdn.com/v4/letter/m/3d9bf3/32.png) [@msz59](https://fortran-lang.discourse.group/u/msz59)
#### Post date: [October 22, 2021, 9:59pm UTC](https://fortran-lang.discourse.group/t/type-component-with-len-attribute-must-be-default-integer-kind/2139/8 "2021-10-22T21:59:40Z")

</div>

> [@FortranFan](#):
>
> standard-conforming compiler should help produce the output as shown:
> 
> kind(t1%n) = 8  
> kind(t2%n) = 8

Do you mean exactly this very output or just that it should compile and run OK? I hope the latter only, as the standard does not say anything about specific kind values, AFAIK.

But even if assume that the values are just number-of-bytes per single value. Would it be prohibited by the standard that an implementation (is it called _processor_ in the modern, but weird to me, nomenclature?) has just one, 16-bytes `integer` kind? Or maybe two: 4B and 16B?

---

<div class="post-metadata">

### Author: ![fortran4r](https://avatars.discourse-cdn.com/v4/letter/f/9de0a6/32.png) [@fortran4r](https://fortran-lang.discourse.group/u/fortran4r)
#### Post date: [October 22, 2021, 10:25pm UTC](https://fortran-lang.discourse.group/t/type-component-with-len-attribute-must-be-default-integer-kind/2139/9 "2021-10-22T22:25:23Z")

</div>

I personally think real(8) and integer(8) are very concise and expressive. In contrast, real(real64) and integer(int64) look very weird. Real already means real number, which makes real(real64) look redundant. If you use dp =\> real64, then it is difficult to find a similar alias for int64. Having both real(dp) and integer(int64) in a code looks inconsistent and weird.

PS: I and my colleagues only use GFortran, so I am not worried about code portability.

---

<div class="post-metadata">

### Author: ![FortranFan](https://avatars.discourse-cdn.com/v4/letter/f/96bed5/32.png) [@FortranFan](https://fortran-lang.discourse.group/u/FortranFan)
#### Post date: [October 22, 2021, 10:26pm UTC](https://fortran-lang.discourse.group/t/type-component-with-len-attribute-must-be-default-integer-kind/2139/10 "2021-10-22T22:26:39Z")

</div>

> [@msz59](#):
>
> just that it should compile and run OK?

The standard obviously does not say anything about the KIND values themselves, the listing of ‘8’ will only be relevant to the processor that helped produce shown output.

---

<div class="post-metadata">

### Author: ![themos](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/themos/32/521_2.png) [@themos](https://fortran-lang.discourse.group/u/themos)
#### Post date: [October 22, 2021, 10:43pm UTC](https://fortran-lang.discourse.group/t/type-component-with-len-attribute-must-be-default-integer-kind/2139/11 "2021-10-22T22:43:28Z")

</div>

Perhaps you should consider that others will use this website to pick up hints about correct use of Fortran and your use of a specific compiler’s idiom will make that job harder and help propagate a misunderstanding of the nature of KIND numbers.

You might also consider that people will be less inclined to comment on your posts if they have to convert your code snippets to standard Fortran.

---

<div class="post-metadata">

### Author: ![msz59](https://avatars.discourse-cdn.com/v4/letter/m/3d9bf3/32.png) [@msz59](https://fortran-lang.discourse.group/u/msz59)
#### Post date: [October 23, 2021, 7:56pm UTC](https://fortran-lang.discourse.group/t/type-component-with-len-attribute-must-be-default-integer-kind/2139/12 "2021-10-23T19:56:56Z")

</div>

I fully support @FortranFan and @themos comments on using _hardwired_ literal values for kinds but just out of curiosity:

Are there (m)any modern compilers using kind values other than _byte-length?_ From the abyss of my memory I can recall only old `g77` compiler which used `kind=1` for default, `2` for double length, `3` for 1-byte, `5` for half-length. But it was (a) just before the last dinosaur died, (b) not standard at all, just extension.

---

<div class="post-metadata">

### Author: ![themos](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/themos/32/521_2.png) [@themos](https://fortran-lang.discourse.group/u/themos)
#### Post date: [October 23, 2021, 8:29pm UTC](https://fortran-lang.discourse.group/t/type-component-with-len-attribute-must-be-default-integer-kind/2139/13 "2021-10-23T20:29:37Z")

</div>

The NAG Fortran compiler supports _three_ different kind numbering schemes, to help check that your code makes no unwarranted assumptions.

---

<div class="post-metadata">

### Author: ![shahmoradi](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/shahmoradi/32/3151_2.png) [@shahmoradi](https://fortran-lang.discourse.group/u/shahmoradi)
#### Post date: [October 23, 2021, 10:53pm UTC](https://fortran-lang.discourse.group/t/type-component-with-len-attribute-must-be-default-integer-kind/2139/14 "2021-10-23T22:53:03Z")

</div>

What I frequently use for default kinds is,

```fortran
module Constants_mod
    use iso_fortran_env
    integer, parameter :: IK => int32 ! default Integer Kind
    integer, parameter :: RK => real64 ! default Real Kind
    integer, parameter :: CK => real64 ! default Complex kind
end module

program
    use Constants_mod :: IK, RK
    integer(IK) :: var_IK
    real(RK) :: var_RK
    complex(CK) :: var_CK
end program

```

Why?

1. avoids the use of non-standard non-portable notation.
2. defines the universal default kinds across the entire codebase, such that the behavior of the codebase can be fully controlled from a single module.
3. separates the default kind of complex from real. This may seem somewhat redundant, but it provides much finer control over what should be the default complex kind and what should be real kind across the codebase.

Even if some objects have to be non-default kind, it is likely much better to define those non-default kinds in a base module to be used elsewhere, like:

```fortran
module Constants_mod
    use iso_fortran_env
    integer, parameter :: IK => int32 ! default Integer Kind
    integer, parameter :: IK8 => int8
    integer, parameter :: IK16 => int16
    integer, parameter :: IK32 => int32
    integer, parameter :: IK64 => int64
end module

```

Reasons are the same: if suddenly `selected_integer_kind()` or `selected_real_kind()` is to be used instead of `iso_fortran_env` kinds, this change of behavior only happens in a few lines of a single module (here `Constants_mod`), and nothing else in codebase needs to change.

I would never use `integer(int32)` or `real(real64)` where `int32` or `real64` belong to `iso_fortran_env` unless it is either a simple test, or `int32` / `real64` appear in precisely the same context as defined in the language, which is different from what most think.

---

<div class="post-metadata">

### Author: ![shahmoradi](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/shahmoradi/32/3151_2.png) [@shahmoradi](https://fortran-lang.discourse.group/u/shahmoradi)
#### Post date: [October 24, 2021, 12:30am UTC](https://fortran-lang.discourse.group/t/type-component-with-len-attribute-must-be-default-integer-kind/2139/16 "2021-10-24T00:30:52Z")

</div>

True. The default in my writing is rather misleading (it was not meant to refer to standard default)

---

<div class="post-metadata">

### Author: ![certik](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/certik/32/4_2.png) [@certik](https://fortran-lang.discourse.group/u/certik)
#### Post date: [October 25, 2021, 2:47am UTC](https://fortran-lang.discourse.group/t/type-component-with-len-attribute-must-be-default-integer-kind/2139/18 "2021-10-25T02:47:55Z")

</div>

Here is Steve’s patch: [PDT type parameters are not restricted to default integer](https://gcc.gnu.org/pipermail/fortran/2021-October/056771.html), thanks @kargl!

Indeed, please keep submitting bugs to any compiler that you use.

---

<div class="post-metadata">

### Author: ![epagone](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/epagone/32/252_2.png) [@epagone](https://fortran-lang.discourse.group/u/epagone)
#### Post date: [October 25, 2021, 11:30am UTC](https://fortran-lang.discourse.group/t/type-component-with-len-attribute-must-be-default-integer-kind/2139/20 "2021-10-25T11:30:36Z")

</div>

Thanks @kargl for the patch and thanks @FortranFan for finding and reporting the bug in the first place! A fruitful combined effort.

(I think Harald Anlauf is not in this discourse but I’d like to thank him as well 🙂 )

---

<div class="post-metadata">

### Author: ![epagone](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/epagone/32/252_2.png) [@epagone](https://fortran-lang.discourse.group/u/epagone)
#### Post date: [October 25, 2021, 2:32pm UTC](https://fortran-lang.discourse.group/t/type-component-with-len-attribute-must-be-default-integer-kind/2139/22 "2021-10-25T14:32:16Z")

</div>

Oh, my bad for selecting the wrong user to tag (with a subtly similar name).

---

<div class="post-metadata">

### Author: ![FortranFan](https://avatars.discourse-cdn.com/v4/letter/f/96bed5/32.png) [@FortranFan](https://fortran-lang.discourse.group/u/FortranFan)
#### Post date: [October 25, 2021, 6:33pm UTC](https://fortran-lang.discourse.group/t/type-component-with-len-attribute-must-be-default-integer-kind/2139/24 "2021-10-25T18:33:40Z")

</div>

> [@epagone](#):
>
> Oh, my bad for selecting the wrong user to tag (with a subtly similar name).

@epagone ,

Just catching up to this thread and noticed your [comment](https://fortran-lang.discourse.group/t/type-component-with-len-attribute-must-be-default-integer-kind/2139/20).

I would have thought you were referring to this thread at comp,lang.fortran from Nov-Dec 2017: [https://groups.google.com/g/comp.lang.fortran/c/NDE6JKTFbNU/m/YRtjs7ahBQAJ](https://groups.google.com/g/comp.lang.fortran/c/NDE6JKTFbNU/m/YRtjs7ahBQAJ)
