We had some experience with @_cdecl
and there were a few issues we hit:
@_cdecl
cannot control the visibility of the symbol. If the function is made public, it appears in the swift interface and causes conflicts when it is also present in a C header in the same module.- The return value is always autoreleased. E.g.
@_cdecl func MyObjectCopyDescription(_ obj: MyObjectPointer?) -> CFString
does not return a retained CFString. - Compiler does not help with nil checking and it's an undefined behavior when NULL is passed to a non-Optional argument. We ended up making everything Optional and force unwrapping them to deterministically crash.
I think it's better to follow the pattern of @objc @implementation
where the function needs to match the declaration in a C header. It would be easier than manually matching the arguments and coming up with new annotations in Swift.