Error[8]: Undefined offset: 4, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

将Swift字符串数组转换为C字符串数组指针

您可以像如何通过使用char
**参数将Swift字符串数组传递给C函数中的步骤类似。由于

const
参数数组的-ness 不同 ,并且存在一个终止符
nil
(一定不能传递给
strdup()
),因此它有所不同。

这是应该如何工作的:

let array: [String?] = ["name1", "name2", nil]// Create [UnsafePointer<Int8>]:var cargs = array.map { [+++].flatMap { UnsafePointer<Int8>(strdup([+++])) } }// Call C function:let result = command(&cargs)// Free the duplicated strings:for ptr in cargs { free(UnsafeMutablePointer(mutating: ptr)) }


)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
Error[8]: Undefined offset: 5, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

将Swift字符串数组转换为C字符串数组指针

您可以像如何通过使用char
**参数将Swift字符串数组传递给C函数中的步骤类似。由于

const
参数数组的-ness 不同 ,并且存在一个终止符
nil
(一定不能传递给
strdup()
),因此它有所不同。

这是应该如何工作的:

let array: [String?] = ["name1", "name2", nil]// Create [UnsafePointer<Int8>]:var cargs = array.map { .flatMap { UnsafePointer<Int8>(strdup([+++])) } }// Call C function:let result = command(&cargs)// Free the duplicated strings:for ptr in cargs { free(UnsafeMutablePointer(mutating: ptr)) }


)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
将Swift字符串数组转换为C字符串数组指针_随笔_内存溢出

将Swift字符串数组转换为C字符串数组指针

将Swift字符串数组转换为C字符串数组指针,第1张

将Swift字符串数组转换为C字符串数组指针

您可以像如何通过使用char
**参数将Swift字符串数组传递给C函数中的步骤类似。由于

const
参数数组的-ness 不同 ,并且存在一个终止符
nil
(一定不能传递给
strdup()
),因此它有所不同。

这是应该如何工作的:

let array: [String?] = ["name1", "name2", nil]// Create [UnsafePointer<Int8>]:var cargs = array.map { .flatMap { UnsafePointer<Int8>(strdup()) } }// Call C function:let result = command(&cargs)// Free the duplicated strings:for ptr in cargs { free(UnsafeMutablePointer(mutating: ptr)) }


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5642156.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存