Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
1 View

Using INTEGER(8) in an INTEGER(4) interface

Hi,

I have a question regarding the use of integers of different kind. I am using a library (Intel MKL) which requires INTEGER(4). However, calling this library with variables of kind INTEGER(8) produces identical results. 

I have also tested this myself by calling my own method taking an INTEGER(4) with an INTEGER(8).

However, the other way around does not work: calling a method taking an INTEGER(8) with an INTEGER(4).

Is this behavior guaranteed with Intel Fortran?

Jens

 

 

0 Kudos
3 Replies
Highlighted
Valued Contributor II
1 View

Apparently the routine you

Apparently the routine you are calling does not have an explicit interface (via a module for instance), otherwise I would have expected the compiler to complain about the mismatch. The problem with passing an INTEGER(8) variable where an INTEGER(4) variable is expected is that this works by coincidence only. It would go wrong if you were to pass an array: the four extra bytes in the INTEGER(8) variable are now interpreted as the second element of the INTEGER(4) array.

So: do not do that!

0 Kudos
Highlighted
Beginner
1 View

Yes, in this case there is no

Yes, in this case there is no explicit interface.

I was just looking for a logical explanation to why I see this behavior - thanks.

Jens

0 Kudos
Highlighted
1 View

>> I am using a library

>> I am using a library (Intel MKL) which requires INTEGER(4). However, calling this library with variables of kind INTEGER(8) produces identical results.

If the argument was INTENT(IN) .AND. the value was less than (+/-) 2G, then it may work... but fix your code, and use the MKL module defined interfaces.

If the argument was INTENT(OUT) .OR. INTENT(INOUT), then for the IN portion of the call see above, but for the out portion of the call the 4 bytes of the most significant bytes of your supplied arguments would remain unchanged. Example, if you pass in an argument of less than +2G,  you would not be able to receive a result of -nn.

Jim Dempsey

0 Kudos