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

How to write C_INT32_T value in fortran?

steve_o_
Beginner
239 Views

I'm writing a hashing function using unsigned 32 bit integers, however I'm not sure if it can be written/printed? Haven't seen any documentation

What's the best method to write/print a c_int32_t integer in fortran ? In C printf would use PRIu32

 

 

0 Kudos
3 Replies
Arjen_Markus
Honored Contributor I
239 Views

I would say: copy the bits into a 64-bits integer and print that. I have not tested it but try:

i64 = transfer( [0, unsigned_int32], i64 )

(or the other way around?) Or use the bit manipulation routines.

Steve_Lionel
Black Belt Retired Employee
239 Views

In Intel Fortran, you could use ZEXT(val,C_INT64_T). That is an extension, though widely implemented. In standard Fortran Arjen's suggestion is clever and workable. Unfortunately the various bit intrinsics, such as IBITS, don't allow changing the kind of the result. You could do something like IAND(INT(val,C_INT64_T),Z'00000000FFFFFFFF'), but that looks awkward.

Example:

use ISO_C_BINDING
integer(4) val
val = -214748364
print ('(Z8.8)'), IAND(INT(val,C_INT64_T),Z'00000000FFFFFFFF')
end
D:\Projects>ifort /stand t.f90
Intel(R) Visual Fortran Intel(R) 64 Compiler for applications running on
 Intel(R) 64, Version 18.0.2.185 Build 20180210
Copyright (C) 1985-2018 Intel Corporation.  All rights reserved.

Microsoft (R) Incremental Linker Version 14.13.26129.0
Copyright (C) Microsoft Corporation.  All rights reserved.

-out:t.exe
-subsystem:console
t.obj

D:\Projects>t.exe
F3333334

 

steve_o_
Beginner
239 Views

I had thought of transfer but ZEXT works and is neater, thanks

 

Reply