我应该如何创建一个 (const char **) 以将其传递给 C 函数?
假设我的 const char ** 被命名为prompts
:
user := 'User:' copyToHeap: #malloc:.
pwd := 'Password:' copyToHeap: #malloc:.
prompts := (ByteArray new: 64) copyToHeap: #malloc:.
prompts copyAt: 0 from: (user referentAddress asByteArraySize: 32) size: 4 startingAt: 1.
prompts copyAt: 31 from: (pwd referentAddress asByteArraySize: 32) size: 4 startingAt: 1.
一个 64 位数组也是如此prompts
,其中前 32 位是指向的指针,user
而后 32 位是指向 的指针pwd
。
但是 C 函数不起作用。在 GemStone 中可以正常工作:
prompts := CByteArray gcMalloc: 16.
user := CByteArray withAll: 'User:'.
pwd := CByteArray withAll: 'Password:'.
prompts uint64At: 0 put: user memoryAddress.
prompts uint64At: 8 put: pwd memoryAddress.