[swift-users] Having a hard time with C interop (callbacks)

Rick Mann rmann at latencyzero.com
Tue Apr 18 18:18:58 CDT 2017

I'm trying to use an API with a complicated callback structure. You pass a struct with a set of pointers to callbacks to a function, along with a pointer to a buffer it fills out. Here's an elided version of the C and Swift code:


This compiles, but I get a runtime error in the unsafeBitCast() call (mismatched sizes) on line 56.

I realize unsafeBitCast() is dangerous, but I was relying Quinn's post in the Apple Dev Forums suggesting it was the best way to go. However, I'm pretty sure I'm using it incorrectly here.

I can't seem to get Xcode to show me its Swift interpretation of the header file. Sometimes it does, sometimes it doesn't.

But can someone please help me get the pointer conversions right for this?

Thank you very much.

Rick Mann
rmann at latencyzero.com

More information about the swift-users mailing list