- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
How do I convert/cast a C_PRT pointer into a HANDLE? The TRANSFER instrinsic function does not work in this case. Please help!
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page