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

What should I replace INTEGER*4 with?

anthonyrichards
New Contributor III
553 Views

I understand that 'portable' or standard conforming code uses specification statements such as REAL(DOUBLE) rather than REAL*8. However, if I wish to replace all my INTEGER*4 specifications, I am left with a bewidering set of choices, such as INTEGER(LONG), INTEGER(UINT), INTEGER(SINT) etc. Here is an example of what's available from DFWINTY: (I use CVF 6.6C)

integer, parameter :: POINTER_LEN = INT_PTR_KIND() ! 4 for WIN32 systems
integer, parameter :: HANDLE = POINTER_LEN ! INTEGER(4/8)
integer, parameter :: DWORD = 4 ! INTEGER(4)
integer, parameter :: ULONG = 4 ! INTEGER(4)
integer, parameter :: LONG = 4 ! INTEGER(4)
integer, parameter :: UINT = 4 ! INTEGER(4)
! The S (for signed) is to avoid conflict with the INT intrinsic
integer, parameter :: SINT = 4 ! INTEGER(4)
integer, parameter :: ENUM = 4 ! INTEGER(4)
integer, parameter :: BOOL = 4 ! INTEGER(4)

Why are there so many partameterised choices for thelength '4'? Which one should I use?

0 Kudos
2 Replies
Steven_L_Intel1
Employee
553 Views
It depends on what you want to use it for. The named constants defined in IFWINTY are for use when calling Win32 API routines where each argument, structure field and return value are documented using names like these (either from C or from the header files Microsoft provides to MSVC.)

So if you are declaring things for use with Win32 API calls, then use the appropriate named constant that matches the MS documentation. HANDLE is a particularly important one to get right as it is different between 32 and 64-bit Windows.

If you're not calling Win32 API code but are calling C, then use the kind constants defined in ISO_C_BINDING.

If you have a need for an integer that will hold a particular number of decimal digits, ise the SELECTED_INT_KIND intrinsic to select it, though I don't recommend using a value lower than 9 for the argument unless required as use of smaller than 32-bit integers can slow down code. This is useful when you want more than 9 digits.

If you want an integer that holds an address, use INT_PTR_KIND() to get that value, or from ISO_C_BINDING, C_PTR.

Otherwise, if all you want is the default integer kind, just say INTEGER with no kind.
0 Kudos
Steven_L_Intel1
Employee
553 Views
Ah, I just noticed you said CVF. Then forget mention of ISO_C_BINDING. The rest holds. For portability, use either SELECTED_INT_KIND to define a constant or let it default.
0 Kudos
Reply