| 1 |
# kind(x): Kind of an Entity |
| 2 |
|
| 3 |
Kind of an entity. |
| 4 |
|
| 5 |
## Declaration |
| 6 |
|
| 7 |
### Syntax |
| 8 |
|
| 9 |
```fortran |
| 10 |
retval = kind(x) |
| 11 |
integer function kind(x) |
| 12 |
``` |
| 13 |
|
| 14 |
### Arguments |
| 15 |
|
| 16 |
`x` the input value, can be logical, integer, real, complex, or character. It |
| 17 |
may be a scalar or array valued i.e., any intrinsic type. |
| 18 |
|
| 19 |
### Return values |
| 20 |
|
| 21 |
The return value is of integer type and of default integer kind. |
| 22 |
|
| 23 |
## Description |
| 24 |
|
| 25 |
**kind(x)** returns the kind parameter of the input argument `x`. |
| 26 |
|
| 27 |
## Types |
| 28 |
|
| 29 |
Supported argument types are logical, integer, real, complex, or character. |
| 30 |
|
| 31 |
```fortran |
| 32 |
module lfortran_intrinsic_kind |
| 33 |
implicit none |
| 34 |
contains |
| 35 |
|
| 36 |
integer function kind(x) result(r) |
| 37 |
logical(4), intent(in) :: x |
| 38 |
r = 4 |
| 39 |
end function |
| 40 |
|
| 41 |
integer function skind(x) result(r) |
| 42 |
real(4), intent(in) :: x |
| 43 |
r = 4 |
| 44 |
end function |
| 45 |
|
| 46 |
integer function dkind(x) result(r) |
| 47 |
real(8), intent(in) :: x |
| 48 |
r = 8 |
| 49 |
end function |
| 50 |
|
| 51 |
integer function lkind(x) result(r) |
| 52 |
logical(4), intent(in) :: x |
| 53 |
r = 4 |
| 54 |
end function |
| 55 |
|
| 56 |
end module |
| 57 |
``` |
| 58 |
|
| 59 |
## Examples |
| 60 |
|
| 61 |
```fortran |
| 62 |
program intrinsics_kind |
| 63 |
use lfortran_intrinsic_kind, only: kind |
| 64 |
implicit none |
| 65 |
logical :: l4d |
| 66 |
logical(4) :: l4 |
| 67 |
print *, kind(l4d) |
| 68 |
print *, kind(l4) |
| 69 |
end program |
| 70 |
``` |
| 71 |
|
| 72 |
**Result:** |
| 73 |
|
| 74 |
``` |
| 75 |
4 |
| 76 |
4 |
| 77 |
``` |
| 78 |
|
| 79 |
## See Also |
| 80 |
|
| 81 |
None. |