[swift-evolution] Rewrite imported C function signatures

Brent Royal-Gordon brent at architechies.com
Fri Mar 25 23:53:51 CDT 2016

> As you can observe, that old-style signature is highly error prone, does not comply with swift guidelines, it is difficult to understand, etc. My opinion is that there should be some syntax to rewrite the signature to avoid those issues. For instance, a possible syntax could be:
> #mapsignature(socket(_:,_:,_:)->Int32)
> func socket(domain:SocketDomain, type:SocketType, protocol:SocketProtocol) -> socket_t? {
> 	let result = socket(domain.rawValue, type.rawValue, protocol.rawValue)
> 	if result == -1 {
> 		return nil
> 	}
> 	else{
> 		return result
> 	}
> }

What's wrong with just overloading it like this without hiding the original? That way you can start by directly porting (perhaps even mechanically converting) the code and later refine it to use the nicer Swift-style overload.

Brent Royal-Gordon

More information about the swift-evolution mailing list