[swift-evolution] [Pitch] String revision proposal #1

Ben Rimmington me at benrimmington.com
Sun Apr 2 20:22:49 CDT 2017


Re: <https://github.com/apple/swift-evolution/pull/662>

### C String Interop

Will the `init(cString: UnsafePointer<UInt8>)` API be deprecated in Swift 4 mode?

<https://github.com/apple/swift/blob/8f3bc160c56461789261d2555dc5485c0484aad5/stdlib/public/core/CString.swift#L55-L63>

It was added by SE-0107 to avoid unsafe pointer conversions:

<https://github.com/apple/swift-evolution/blob/master/proposals/0107-unsaferawpointer.md#cstring-conversion>

### C Primitive Types

Will the `CChar` typealias be *unsigned* on some platforms?

<https://github.com/apple/swift/blob/8f3bc160c56461789261d2555dc5485c0484aad5/stdlib/public/core/CTypes.swift#L15-L19>

Could some of those typealiases in CTypes.swift be moved to a C header, so that they're always imported as the correct types for each platform?

//===--- CTypes.h ------===//
typedef char               CChar;
typedef signed char        CSignedChar;
typedef unsigned char      CUnsignedChar;
typedef short              CShort;
typedef unsigned short     CUnsignedShort;
typedef int                CInt;
typedef unsigned int       CUnsignedInt;
typedef long               CLong;
typedef unsigned long      CUnsignedLong;
typedef long long          CLongLong;
typedef unsigned long long CUnsignedLongLong;
typedef float              CFloat;
typedef double             CDouble;

For example, CTypes.swift for 64-bit Windows currently has:
* `CLong     = Int32` versus `CUnsignedLong     = UInt`,
* `CLongLong = Int`   versus `CUnsignedLongLong = UInt64`.



More information about the swift-evolution mailing list