# Help on input type error: passed INTEGER(4) to INTEGER(2)

**URL:** <https://fortran-lang.discourse.group/t/help-on-input-type-error-passed-integer-4-to-integer-2/6002>\
**Category:** Uncategorized\
**Created:** [June 19, 2023, 1:45pm UTC](https://fortran-lang.discourse.group/t/help-on-input-type-error-passed-integer-4-to-integer-2/6002 "2023-06-19T13:45:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![honglongecon](https://avatars.discourse-cdn.com/v4/letter/h/ce7236/32.png) [@honglongecon](https://fortran-lang.discourse.group/u/honglongecon)\
**Post date:** [June 19, 2023, 1:45pm UTC](https://fortran-lang.discourse.group/t/help-on-input-type-error-passed-integer-4-to-integer-2/6002/1 "2023-06-19T13:45:06Z")

</div>

Hi everyone,

I have a function that is f(x), where x is set as `integer(2), intent(in) :: x`

When I type f(1), it shows the following error: `Type mismatch in argument 'x' at (1); passed INTEGER(4) to INTEGER(2)`

I think I can fix this problem by simply changing the function setting to `integer(4), intent(in) :: x`.

However, as a newbie in Fortran, I wonder how can I input “1” as an integer(2).

Thanks so much, and I look forward to hearing from you!

Best,  
Long

---

<div class="post-metadata">

**Author:** ![PierU](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/pieru/32/1848_2.png) [@PierU](https://fortran-lang.discourse.group/u/PierU)\
**Post date:** [June 19, 2023, 2:03pm UTC](https://fortran-lang.discourse.group/t/help-on-input-type-error-passed-integer-4-to-integer-2/6002/2 "2023-06-19T14:03:34Z")

</div>

The general way to express a constant with a kind that is not the default kind is `<value>_<kind>`.

`1_2` is therefore `1` as an `integer(2)`

It can be more readable to use a constant:

```auto
integer, parameter :: ik2=2
call f(1_ik2)

```

But some constants are readily available in the `iso_fortran_env` module:

```auto
use iso_fortran_env, only : int16
call f(1_int16)
...
...
subroutine f(x)
use iso_fortran_env, only : int16
integer(int16), intent(in) :: x

```

---

<div class="post-metadata">

**Author:** ![honglongecon](https://avatars.discourse-cdn.com/v4/letter/h/ce7236/32.png) [@honglongecon](https://fortran-lang.discourse.group/u/honglongecon)\
**Post date:** [June 19, 2023, 2:29pm UTC](https://fortran-lang.discourse.group/t/help-on-input-type-error-passed-integer-4-to-integer-2/6002/3 "2023-06-19T14:29:38Z")

</div>

Thanks, @PierU! This is super helpful!

---

<div class="post-metadata">

**Author:** ![RonShepard](https://avatars.discourse-cdn.com/v4/letter/r/a3d4f5/32.png) [@RonShepard](https://fortran-lang.discourse.group/u/RonShepard)\
**Post date:** [June 19, 2023, 4:14pm UTC](https://fortran-lang.discourse.group/t/help-on-input-type-error-passed-integer-4-to-integer-2/6002/4 "2023-06-19T16:14:22Z")

</div>

It is a bad idea to hard code literal kind values, for a variety of reasons. You might also want to combine the two approaches suggested by @PierU with something like:

```auto
use iso_fortran_env, only : ik2 => int16
!...
call f(1_ik2)

```

Then if you do ever want to change the kind, you would just need to change it a single time in the use statement rather than in all the declarations and constants throughout the code.

---

<div class="post-metadata">

**Author:** ![VladimirF](https://avatars.discourse-cdn.com/v4/letter/v/e9a140/32.png) [@VladimirF](https://fortran-lang.discourse.group/u/VladimirF)\
**Post date:** [June 21, 2023, 5:26am UTC](https://fortran-lang.discourse.group/t/help-on-input-type-error-passed-integer-4-to-integer-2/6002/5 "2023-06-21T05:26:47Z")

</div>

It is indeed a bad idea and placing “magic numbers” in code is [Magic number (programming) - Wikipedia](https://en.wikipedia.org/wiki/Magic_number_(programming)) a bad idea in programming in general.

Named constants are the way to go even if one decides to set the value just to 2 instead of int16 in a top-most module.
