I would like to constrain a generic to a type that can be represented in C. Is there a protocol or type in the Swift standard library that all C types conform to?
func doWithCType<T:CRepresentable>(cValue: T) {
// do thing with C type
}
If not a CRepresentable, maybe a CStruct type?
Clues:
Using this C type:
typedef struct {
int hodor;
} Hodor;
I force casted a struct to an incompatible type (causing a crash). This was the error message: Could not cast value of type '__C.Hodor' (0x1035c0700) to 'Swift.CVarArg' (0x107196240).
I can't find "__C" anywhere, but I'm hopeful that there's a distinction for the C types.
Is Swift.CVarArg
what you need? It is for types that can be passed through C's va_list
mechanism for varargs.
There is also CVaListPointer
, which is equivalent to va_list *
. That appears in the arguments to String(format:)
.
https://developer.apple.com/documentation/swift/cvararg https://developer.apple.com/documentation/swift/cvalistpointer
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With