How to pass (void *) 8 to a C function from Swift


(Eddy Hahn) #1

Hi,

I have a C function (foo(void*) value) and I need to call it from Swift. Swift imports the parameter as UnsafeMutableRawPointer. I cannot figure out how to create one with the memory address (such as 8).

foo( (void *) 8);

Any idea

Thanks,

Eddy


(Joe Groff) #2

You can construct pointers from bit patterns using the bitPattern: initializers, e.g. UnsafeMutableRawPointer(bitPattern: 8)!


(Eddy Hahn) #3

Thank you!