{"id":16314,"date":"2016-11-08T16:26:54","date_gmt":"2016-11-08T21:26:54","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=16314"},"modified":"2016-11-08T16:32:10","modified_gmt":"2016-11-08T21:32:10","slug":"passing-an-array-of-strings-from-swift-to-c","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2016\/11\/08\/passing-an-array-of-strings-from-swift-to-c\/","title":{"rendered":"Passing an Array of Strings From Swift to C"},"content":{"rendered":"<p><a href=\"https:\/\/oleb.net\/blog\/2016\/10\/swift-array-of-c-strings\/\">Ole Begemann<\/a>:<\/p>\n<blockquote cite=\"https:\/\/oleb.net\/blog\/2016\/10\/swift-array-of-c-strings\/\">\n<p>The type checker allows you to <a href=\"https:\/\/developer.apple.com\/library\/content\/documentation\/Swift\/Conceptual\/BuildingCocoaApps\/InteractingWithCAPIs.html#\/\/apple_ref\/doc\/uid\/TP40014216-CH8-ID17\">pass a <code>String<\/code> value to an <code>UnsafePointer&lt;Int8&gt;<\/code> or <code>UnsafePointer&lt;UInt8&gt;<\/code> parameter<\/a>. When you do that, the compiler will transparently create a buffer containing the UTF-8-encoded, null-terminated string, and pass a pointer to that buffer to the function.<\/p>\n<p>[&#8230;]<\/p>\n<p>However, some C functions take an array of strings (a <code>char **<\/code> or <code>char *[]<\/code>), and there is no built-in support in Swift for passing a <code>[String]<\/code> to a <code>char **<\/code> parameter.<\/p>\n<p>[&#8230;]<\/p>\n<p>The full type of the <code>strlen<\/code> function as imported by Swift looks like this[&#8230;]<\/p>\n<\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Ole Begemann: The type checker allows you to pass a String value to an UnsafePointer&lt;Int8&gt; or UnsafePointer&lt;UInt8&gt; parameter. When you do that, the compiler will transparently create a buffer containing the UTF-8-encoded, null-terminated string, and pass a pointer to that buffer to the function. [&#8230;] However, some C functions take an array of strings (a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"","apple_news_api_id":"","apple_news_api_modified_at":"","apple_news_api_revision":"","apple_news_api_share_url":"","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[45,46,571,71,901],"class_list":["post-16314","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-c","tag-languagedesign","tag-memory-management","tag-programming","tag-swift-programming-language"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/16314","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=16314"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/16314\/revisions"}],"predecessor-version":[{"id":16315,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/16314\/revisions\/16315"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=16314"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=16314"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=16314"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}