Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

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

Jens_E_
New Contributor I
952 Views

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
Arjen_Markus
Honored Contributor I
952 Views

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
Jens_E_
New Contributor I
952 Views

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
jimdempseyatthecove
Honored Contributor III
952 Views

>> 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
Reply