[swift-corelibs-dev] CChar vs Int8

Tony Parker anthony.parker at apple.com
Mon Jan 4 15:20:13 CST 2016


Hi Luke,

> On Jan 2, 2016, at 8:28 PM, Luke Howard via swift-corelibs-dev <swift-corelibs-dev at swift.org> wrote:
> 
> Many Foundation APIs use Int8 instead of CChar when representing C strings, e.g.:
> var UTF8String: UnsafePointer <https://developer.apple.com/library/mac/documentation/Swift/Reference/Swift_UnsafePointer_Structure/index.html#//apple_ref/swift/struct/s:VSs13UnsafePointer><Int8 <https://developer.apple.com/library/mac/documentation/Swift/Reference/Swift_Int8_Structure/index.html#//apple_ref/swift/struct/s:VSs4Int8>> { get }
> I don’t know if/when Swift will be ported to a platform where the character type is unsigned but perhaps it would be good to update these to take CChar instead?
> 
> — Luke
> 

I’m not really sure why it’s imported to Swift as an unsafe pointer to Int8 anyway. The Objective-C code uses char:

@property (nullable, readonly) __strong const char *UTF8String NS_RETURNS_INNER_POINTER;	// Convenience to return null-terminated UTF8 representation

- (nullable instancetype)initWithUTF8String:(const char *)nullTerminatedCString;

- Tony

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-corelibs-dev/attachments/20160104/742639a9/attachment.html>


More information about the swift-corelibs-dev mailing list