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

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

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

3 Likes

Thank you!