Question

Recently, I had to increase the precision for some integer variables in my code. Now I have a mixing of integer kinds and I wonder about the basic stuff about them. For example, suppose I have this variables:

integer, parameter    :: idp = selected_int_kind(18) 
integer, parameter    :: isp = selected_int_kind(8) 

integer(isp)       :: a,i
integer(idp)       :: da,di

The asignment a=da is ok? and what about da=1_isp? or da=da+1? In the case of a loop do di=1,da is allowed? or I have to do do di=1_idp,da?

In the case:

subroutine stackof(b,c)
    integer(isp)       :: b,c
    .....

can I call stackof(1_isp,da)

Thank you.

Was it helpful?

Solution

The asignment a=da is ok?

Yes, if da is in the isp range, you might get warnings though.

and what about da=1_isp?

Yes, see above.

or da=da+1?

Same.

In most cases, I think it's worth to use explicit casting like da = int(a, kind=idp). That will also avoid warnings by the compiler.

In the case of a loop do di=1,da is allowed?

Tricky, I guess it might work, if the compiler supports long integers as loop counters. But, I would be cautious with that.

can I call stackof(1_isp,da)

No, type, kind and rank have to match.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top