Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

Convert/cast a C_PRT pointer into a HANDLE

Syed_R_
Beginner
644 Views

How do I convert/cast a C_PRT pointer into a HANDLE? The TRANSFER instrinsic function does not work in this case. Please help!

0 Kudos
3 Replies
Steven_L_Intel1
Employee
644 Views

It doesn't?

E:\Projects>type t.f90
use iso_c_binding
use ifwinty, only: handle
character(10) string
integer(handle) :: h
type(c_ptr) :: cp

print *, loc(string)
cp = c_loc(string)
h = transfer(cp, 0_handle)
print *, h
end
E:\Projects>ifort t.f90
Intel(R) Visual Fortran Compiler XE for applications running on IA-32, Version 14.0.0.103 Build 20130728
Copyright (C) 1985-2013 Intel Corporation.  All rights reserved.

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

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

E:\Projects>t.exe
     1586660
     1586660

0 Kudos
Syed_R_
Beginner
644 Views

That works. I have another question to convert the reverse.

But how do I convert/cast a HANDLE into a C_PRT pointer? The TRANSFER instrinsic function does not work in this case. Please help!

0 Kudos
Steven_L_Intel1
Employee
644 Views

Yes, TRANSFER does work. Why do you think it doesn't?

C:\Projects>type t.f90
use iso_c_binding
use ifwinty, only: handle
character(10) string
integer(handle) :: h
type(c_ptr) :: cp
character(10), pointer :: sp

string = 'abcdefghij'
h = loc(string)
print *, h
cp = transfer(h, cp)
call c_f_pointer (cp, sp)
print *, sp
end

C:\Projects>ifort /nologo t.f90

C:\Projects>t.exe
     2585868
 abcdefghij

0 Kudos
Reply